如何为包含的小部件设置与容器不同的样式表
我有一个部分是顶部小部件,顶部小部件的颜色是灰色,并且我在顶部小部件内放置了几个小部件,QComboBox、QLineEdit 和 2 QButton。
但是当我右键单击 QLineEdit 时,窗口的默认上下文颜色为灰色,或者当我打开 QComboBox 时背景颜色为灰色。
我已将这两个小部件的背景颜色设置为白色,但它不起作用。
我该如何解决这个问题?
I have a section that is a top widget, the color of the top widget is gray, and I've put several widgets inside the top widget, QComboBox, QLineEdit and 2 QButton.
But when I right click on QLineEdit, the color of default context of window is gray, or when I open the QComboBox the color of background is gray.
I've set the background color of these two widgets to white but it doesn't work.
How can I fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
样式表传播到所有子窗口小部件,因此您必须使用正确的选择器来限制它们的范围。由于上下文菜单是 QLineEdit 的子菜单,因此它也会受到影响。
有关详细信息,请参阅样式表语法 - 选择器类型 。
The style sheet propagates to all the child widgets, so you have to limit their range by using the right selectors. Since the context menu is a child of the QLineEdit it is also affected.
See The Style Sheet Syntax - Selector Types for details.