当前位置: 代码迷 >> QT开发 >> 关于QTableWidget的两个有关问题
  详细解决方案

关于QTableWidget的两个有关问题

热度:60   发布时间:2016-04-25 04:57:51.0
关于QTableWidget的两个问题
先上代码:

C/C++ code
#include <QtGui>class Widget : public QWidget{    Q_OBJECTprivate:    QTableWidget *tableWidget;    QPushButton *showButton;public:    Widget(QWidget *parent = 0);    public slots:        void ClickedShowButton();};Widget::Widget(QWidget *parent /* = 0 */): QWidget(parent){    resize(400, 300);    tableWidget = new QTableWidget(3, 3, this);    showButton = new QPushButton("show", this);    QVBoxLayout *layout = new QVBoxLayout;    layout->addWidget(tableWidget);    layout->addWidget(showButton);    setLayout(layout);    connect(showButton, SIGNAL(clicked()),         this, SLOT(ClickedShowButton()));    tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);    tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);    for(int i=0; i<3; i++)    {        for(int j=0; j<3; j++)        {            QString str = QString::number(i) + QString::number(j);            tableWidget->setItem(i, j, new QTableWidgetItem(str));        }    }}void Widget::ClickedShowButton(){    QMessageBox::information(this, "AA", "Show");}#include "main.moc"int main(int argc, char **argv){    QApplication app(argc, argv);    Widget *widget = new Widget;    widget->show();    return app.exec();}


问题:
1:选中一行时(我设定了行选择),列表头的字体会变粗,怎么才能让它们不变粗呢?
2:如果我选中了tableWidget中的某一行,然后我点击了另一个控件(如代码中的showButton),怎么才能让刚才的那一行保持选中状态(保持高亮)?

------解决方案--------------------
1.用QSS设置
CSS code
QTableWidget QHeaderView::section{    font:...;}
  相关解决方案