Qt style sheet syntax doesn't work?

Mojtaba Ahmadi picture Mojtaba Ahmadi · May 31, 2013 · Viewed 7.3k times · Source

I'm using Qt 5.0.1 . I want to use style sheet syntax to customize the features of widget and it's elements.

but some syntaxes like QLineEdit { color: red } or

QPushButton#evilButton:pressed {
     background-color: rgb(224, 0, 0);
     border-style: inset;
 }

don't work and compiler gives error.

I changed some syntaxes and got answer.for example:

QPushButton#evilButton {
 background-color: red;
 border-style: outset;
 border-width: 2px;
 border-radius: 10px;
 border-color: beige;
 font: bold 14px;
 min-width: 10em;
 padding: 6px;

}

converted to:

mypushbutton->setStyleSheet("background-color:purple;"
                     "border-style:inset;"
                     "border-width: 4px;"
                     "border-color: green;"
                     "border-radius: 10px;"
                     "font: bold 14px;"
                     "min-width: 10em;"
                     "padding: 6px;"
                     );

in fact I used another function to do that.but I couldn't change the first codes and don't know what to do...what should I do?should I include something or something else is the problem?I used this page to learn the style sheet syntax.even the example of my own Qt aren't work and just error raises...!!!???

Answer

Ruslan Salikhov picture Ruslan Salikhov · Jun 1, 2013

Tried your example and it works on Qt5

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);

    this->setStyleSheet(
                "QPushButton#evilButton {"
                "background-color: red;"
                "border-style: outset;"
                "border-width: 2px;"
                "border-radius: 10px;"
                "border-color: beige;"
                "font: bold 14px;"
                "min-width: 10em;"
                "padding: 6px; }"
                );
}

btw I store qss in file and load styles from it