简体   繁体   English

限制样式表对父窗口小部件的影响?

[英]Limiting the effects of a stylesheet to the parent widget?

I am setting the background color of a QWidget subclass. 我正在设置QWidget子类的背景颜色。 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). 当我使用样式表执行此操作时, QWidget其他组件的样式会发生变化(例如,PushButton的颜色及其外观会发生变化)。

How do I make sure only the background color of the container widget changes and the rest of the child components remain unchanged? 如何确保仅容器窗口小部件的背景颜色发生更改,其余子组件保持不变?

One way is to specify an ID selector. 一种方法是指定ID选择器。 Make sure to set the objectName of your container widget (with setObjectName() ) and use that name in the CSS selector. 确保设置容器窗口小部件的objectName (使用setObjectName() )并在CSS选择器中使用该名称。 Assuming a widget named MyContainer , you would use something like this: 假设一个名为MyContainer的小部件,您将使用以下内容:

QWidget#MyContainer {...}

尝试!儿童els背景颜色属性的imporant限定符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM