Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

qt

When adding a QComboBox control in Qt Designer, I get a terrible looking, non-native control:

enter image description here

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?

like image 574
Hisham Abboud Avatar asked May 14 '10 22:05

Hisham Abboud


People also ask

How do I make a Qt widget invisible?

1) Subclass your QWidget and use a special/own setVisible() replacement method witch turns on/off the painting of the widget (if the widget should be invisible simply ignore the painting with an overridden paintEvent() method).

Does Qt use CSS?

The concepts, terminology, and syntax of Qt Style Sheets are heavily inspired by HTML Cascading Style Sheets (CSS) but adapted to the world of widgets. Topics: Overview.


1 Answers

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.

like image 63
Shiva Avatar answered Nov 20 '22 19:11

Shiva