How to apply a button stylesheet
-
I placed a stackedwidget in the mainwindow.
And set the background.ui->page1->setStyleSheet("QWidget {background-image: url(:/images/bg.png);}");
ui->page2->setStyleSheet("QWidget {background-image: url(:/images/bg.png);}");
ui->page3->setStyleSheet("QWidget {background-image: url(:/images/bg.png);}");Setting the background of stackedwidget succeeded.
But the button background color inside the stackedWidget doesn't change.ui->button->setStyleSheet("QPushButton {background-color: white; color: rgb(58, 134, 255); border: 2px solid rgb(58, 134, 255);}");
Button background color is not white.
The button background appears as image/bg.png.What did I do wrong?
-
@LISP
Hi,
Your description makes me think ui->button is child one of three pages, if it is so is normal.
"QWidget {background-image: url(:/images/bg.png);}" is too general, all chieldren of page inherit this style.
You have two ways:
Insert your style in design without insert QWidget keyword
Indicate class name "QWidget#NamePage {background-image: url(:/images/bg.png);}"see https://doc.qt.io/qt-5/stylesheet-syntax.html at Conflict Resolution
-
@LISP
Hi,
Your description makes me think ui->button is child one of three pages, if it is so is normal.
"QWidget {background-image: url(:/images/bg.png);}" is too general, all chieldren of page inherit this style.
You have two ways:
Insert your style in design without insert QWidget keyword
Indicate class name "QWidget#NamePage {background-image: url(:/images/bg.png);}"see https://doc.qt.io/qt-5/stylesheet-syntax.html at Conflict Resolution