qss and children objects
-
In Designer I have created QWidget with child QPushButton within that have names widget and btn accordingly. At widget I have set up qss:
#widget { background-color: red; } #widget:hover { background-color: green; } #widget:hover > #btn { background-color: rgb(255, 0, 0); } #widget:!hover > #btn { background-color: rgb(0, 0, 255); }
But color changes only at widget. Why? How its syntax is correct?
-
Hi,
Your error description is not clear. Do you mean your stylesheet only applies to your widget named widget ?
-
Hi,
Your error description is not clear. Do you mean your stylesheet only applies to your widget named widget ?
-
There's no reason for that. From what you wrote, you applied that stylesheet on "widget".
-
Please show your code, I have misunderstood your description.
-
Which version of Qt ?
On which platform ? -
In Designer I have created QWidget with child QPushButton within that have names widget and btn accordingly. At widget I have set up qss:
#widget { background-color: red; } #widget:hover { background-color: green; } #widget:hover > #btn { background-color: rgb(255, 0, 0); } #widget:!hover > #btn { background-color: rgb(0, 0, 255); }
But color changes only at widget. Why? How its syntax is correct?
@magrif said in qss and children objects:
#widget:hover > #btn { background-color: rgb(255, 0, 0); }
Did you try
QWidget:hover > QPushButton { background-color: rgb(255, 0, 0); }
just in case?
And I would start out by testing changing the button without specifying
hover
to eliminate that from being the issue.#widget > #btn { ... /* or */ QWidget > QPushButton { ...
BTW, according to https://doc.qt.io/qt-5/stylesheet-syntax.html#selector-types I do not see that
#widget
is a legal selector in QSS? It only shows acceptingQWidget#widget
? EDIT Oh you said in Designer, maybe it gets translated from what you show? Bear that in mind for my suggestions above. -
@magrif said in qss and children objects:
#widget:hover > #btn { background-color: rgb(255, 0, 0); }
Did you try
QWidget:hover > QPushButton { background-color: rgb(255, 0, 0); }
just in case?
And I would start out by testing changing the button without specifying
hover
to eliminate that from being the issue.#widget > #btn { ... /* or */ QWidget > QPushButton { ...
BTW, according to https://doc.qt.io/qt-5/stylesheet-syntax.html#selector-types I do not see that
#widget
is a legal selector in QSS? It only shows acceptingQWidget#widget
? EDIT Oh you said in Designer, maybe it gets translated from what you show? Bear that in mind for my suggestions above.