Styling the QListItemWidget's Widget
-
I have a QListWidget, and in it are various QListWidgetItem(s). On each QListWidgetItem there is a widget set by
setItemWidget()
.I can style the whole QListWidgetItem
QListWidget::item:selected { background: #efefef; }
But if I want to change the 'color' of the QLabel inside QWidget which is inside QListWidgetItem (selected by ::item) like this
QListWidget::item:selected { background: #efefef; color: white; }
It does not work.
Using CSS I want to change the color of the Item's Widget, on 'selected' state.
More specifcally I want to change the color of the QLabel(s) inside the QWidget which is inside QListWidgetItem.
Is this possible? How can I achieve this?
-
Hi
you have to target QLabel then, not just QListWidget::itemQLabel {
xxxxx
}If it need to be just one, you can use names
QLabel#somename {
xxxxx
} -
@mrjj
I don't think I understand properly.
I have done this beforeQListWidget::item:selected QLabel { background:#efefef; color:white; }
It does styles the QLabels but not on 'selected' state. This applies to the QLabels even when QListWidgetItem is not selected. I want to apply the styles on selected state.
Can you post the complete block.. so I can understand better? -
@candh
I dont think substates affects the children.
so QListWidget::item:selected wont affect QLabel.
Did Not work in my test.Maybe you could use dynamic properties.
https://wiki.qt.io/Dynamic_Properties_and_Stylesheets
so when you click item, you grab the widget and
set the dynamic property. -
@candh
Yes, or on the QListWidget signal for something selected if that fires when you
click on the widgets.
I used the custom/dynamic property to allow stylesheet to define the selection colors. I assume your goal is somewhat the same.