Limiting the effect of a stylesheet on a parent widget?

I set the background color of the QWidget subclass. When I do this using the stylesheet, the styles of other components in the QWidget change (for example, the color of the Push-Button and its appearance).

How can I make sure that only the background color of the container widget changes and the other child components remain unchanged?

+4
source share
2 answers

One way is to specify an identifier. Remember to set the objectName your container's widget (with setObjectName() ) and use that name in the CSS selector. Assuming a widget named MyContainer , you should use something like this:

 QWidget#MyContainer {...} 
+4
source

Give it a try! Define a qualifier on the background color property for child elements.

-1
source

All Articles