如何使 Qt 小部件忽略父小部件上设置的样式表?
在 Qt Designer 中添加 QComboBox 控件时,我得到一个看起来很糟糕的非本机控件:
进一步挖掘,发现两个父控件 QParentWindow 和 QStackedWidget 具有 QComboBox 的样式表正在继承。如果我删除自定义样式,那么我会得到一个本机 QComboBox,如左侧所示。
我怎样才能让 QComboBox (以及一般的小部件)不继承父样式?或者,我如何为 QParentWindow 创建样式,并使其仅是本地的并且不会级联?
When adding a QComboBox control in Qt Designer, I get a terrible looking, non-native control:
On digging further, it turns out that two of the parent controls, QParentWindow and QStackedWidget, have style sheets that QComboBox is inheriting. If I delete the custom styles, then I get a native QComboBox like the one on the left.
How can I have QComboBox (and widgets generally) NOT inherit parent styles? Or, how can I create a style for, say, QParentWindow, and do it so that it's local only and does not cascade?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你无法阻止它级联。但是通过在样式表中使用更具体的选择器,也许您可以仅为您的 QParentWindow 类或特定对象定义属性。
I don't think you can prevent it from cascading. But by using more specific selectors in your stylesheet, maybe you could define properties only for your QParentWindow class or specific object.
您需要定义一个样式,然后将其分配给该对象:
这里“groupBoxSettings”是对象名称。这样,组框中的任何内容都会有自己的风格。
you need to define a style and then assign it to that object:
here "groupBoxSettings" is the object name. This way any thing inside the groupbox they'll have their own style.