开发者

How can I make a Qt widget ignore style sheets set on parent widgets?

开发者 https://www.devze.com 2022-12-30 22:05 出处:网络
When adding a QComboBox control in Qt Designer, I get a terr开发者_JAVA技巧ible looking, non-native control:

When adding a QComboBox control in Qt Designer, I get a terr开发者_JAVA技巧ible looking, non-native control:

How can I make a Qt widget ignore style sheets set on parent widgets?

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?


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.


you need to define a style and then assign it to that object:

QString settingStyle = " QGroupBox#groupBoxSettings {\
        background-color: rgb(248,248,248);\
        border: 1px solid rgb(170, 170, 255);\
        border-radius: 3px;\
        border-color:rgb(170, 170, 255);\
}";


ui->groupBoxSettings->setStyleSheet(settingStyle);

here "groupBoxSettings" is the object name. This way any thing inside the groupbox they'll have their own style.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号