python 在pyqt中应用样式表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2404317/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-04 00:34:33  来源:igfitidea点击:

Applying style sheets in pyqt

pythonqt4pyqtstylesheetpyqt4

提问by Jeba

If i apply a property to a parent widget it is automatically applied for child widgets too.. Is there any way of preventing this?? For example if i set background color as white in a dialog the button,combo boxes and scroll bars looks white as it lacks it native look(have to say it's unpleasant & ugly).. Is there any way that i can apply the stylesheets only to a parent widget not to it's children???

如果我将一个属性应用于父小部件,它也会自动应用于子小部件。有什么办法可以防止这种情况?例如,如果我在对话框中将背景颜色设置为白色,按钮、组合框和滚动条看起来是白色的,因为它缺乏原生外观(不得不说它令人不快和丑陋)。有什么办法可以只应用样式表到父小部件而不是它的孩子???

Experts help please..

请高手帮忙..

回答by Jeba

Found a solution..

找到了解决办法。。

Instead of using

而不是使用

self.groupBox.setStyleSheet("background-color: rgb(255, 255, 255);\n"
                                    "border:1px solid rgb(255, 170, 255);")

use specifically using selector types..

专门使用选择器类型..

self.groupBox.setStyleSheet("QGroupBox { background-color: rgb(255, 255,\
255); border:1px solid rgb(255, 170, 255); }")

This solves the problem..

这解决了问题..