Qt style sheet syntax not working?

I am using Qt 5.0.1. I want to use the style sheet syntax to customize the functions of the widget and its elements.

but some syntaxes like QLineEdit { color: red } or

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

do not work, and the compiler gives an error.

I changed some syntaxes and got an answer. For instance:

 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;" ); 

I actually used a different function for this. But I could not change the first codes and I do not know what to do ... what should I do? Should I include something or something else a problem? I used this page to find out the syntax of the stylesheet. Even the example of my own Qt does not work and just an error occurs ... !!! ???

+4
source share
1 answer

Tried your example and 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 files and load styles from it

+7
source

Source: https://habr.com/ru/post/1483793/


All Articles