PDA

View Full Version : Disabling automatic selection behavior of QTableWidget



MattMI
15th March 2017, 18:55
I have a QTableWidget with 10 rows and 11 columns. Here is some of the initialization:


logTable = new QTableWidget(10, 11, this);
logTable->setSelectionMode(QAbstractItemView::SingleSelectio n);
logTable->setSelectionBehavior(QAbstractItemView::SelectRows );
connect(logTable, SIGNAL(itemSelectionChanged()), this, SLOT(tableSelectionChanged()));

About half of the table cells are filled with QTableWidgetItems and the other half is QLabels. When a user selects a row in the table, the QLabels don't change, so that's why I made the tableSelectionChanged() slot. Inside that slot, I change the stylesheets of all the QLabels, and things work just fine. With the QTableWidgetItems, however, I can't change their appearance inside the slot (the default appearance takes precedence). I use the setBackgroundColor method in the slot to change the QTableWidgetItem background, but it has no effect. Also, the font color in the QTableWidgetItems changes from black to white, which I don't want. How can I disable the default behavior of the QTableWidgetItems, so I can replace it with my own?

jefftee
16th March 2017, 02:41
Have you looked at the QTableWidget::setSelectionMode method? One of the selection modes is QAbstractItemView::NoSelection.

Edit: Sorry, completely missed the code you posted that you already tried! Watching TV and posting, not good!!!