限制样式表对父窗口小部件的影响? [英] Limiting the effects of a stylesheet to the parent widget?

查看:57
本文介绍了限制样式表对父窗口小部件的影响?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设置 QWidget 子类的背景颜色。当我使用样式表执行此操作时, QWidget 中其他组件的样式会更改(例如,PushButton的颜色及其外观会发生变化)。

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?

推荐答案

一种方法是指定ID选择器。确保设置容器小部件的 objectName (使用 setObjectName()),并在CSS选择器中使用该名称。 。假设有一个名为 MyContainer 的小部件,您将使用以下内容:

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 {...}

这篇关于限制样式表对父窗口小部件的影响?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆