Changing the foreground color of sub-elements of selected rows in Qt5.4

158 Views Asked by At

I would like to change the foreground color of cell widgets in a QTableWidget. The hierarchy is the following:

QTableWidget
> QTableWidgetItem[]
>> QLabel
>> QLineEdit
>> QLineEdit
>> QLineEdit
>> QLineEdit

That is, five columns and N rows in a list view. I want the font color of all sub-items to change when a row is selected/highlighted. I am trying to obtain this using QStyleSheet.

Attempts

1) The following does not work, because it changes the color regardless of the selection state:

QTableWidget::item:selected QLabel,
QTableWidget::item:selected QLineEdit {
color: white;
}

2) The following does not work, because QLabel/QLineEdit does not respond to selection-color:

QTableWidget::item:selected QLabel,
QTableWidget::item:selected QLineEdit {
color: #666;
selection-color: white;
}
0

There are 0 best solutions below