Limiting the effects of a stylesheet to the parent widget?

泄露秘密 提交于 2020-01-13 09:55:08

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!