问题
I am setting the background color of a QWidget
subclass. When I do this using a stylesheet, the styles of the other components in the QWidget
change (eg, the color of a PushButton, and its look changes).
How do I make sure only the background color of the container widget changes and the rest of the child components remain unchanged?
回答1:
One way is to specify an ID selector. Make sure to set the objectName
of your container widget (with setObjectName()
) and use that name in the CSS selector. Assuming a widget named MyContainer
, you would use something like this:
QWidget#MyContainer {...}
回答2:
Try !imporant qualifier on child els background color property.
来源:https://stackoverflow.com/questions/11146251/limiting-the-effects-of-a-stylesheet-to-the-parent-widget