Unsolved How can I repaint my QPushButton
-
I'm using Qt5.5 to develop my program.
Here is part of my codeActually i wanna print color green on this Button.
But it didn't work, it still no color.
I'm sure there is no error when i compile it.
But why it doesn't work?
Please Help! -
Can u try with style sheet for your requirements?
-
@victor-wang
Doc says http://doc.qt.io/qt-4.8/qpalette.html#detailsWe strongly recommend that you use the default palette of the current style (returned by QApplication::palette()) and modify that as necessary. This is done by Qt's widgets when they are drawn. To modify a color group you call the functions setColor() and setBrush(), depending on whether you want a pure color or a pixmap pattern.
Here is an example which may help you .
One more simple example is here .
-
@Ratzz
Sorry, i can't see any thing in your example.
Could u post again? -
@victor-wang
Did you read the doc I posted? -
A way by style sheet:
ui->pushButton->setStyleSheet("background:#CC892B;");
-
@Ratzz
Yes, i assume that it means i have to change the code like thisui->pushbuttonpt_land_resultlight->setpalette(QApplication::palette())
I'm not quite sure so i want to see the example to evidence my hypothesis.
Am i right? -
Hi @victor-wang
To set the color of your pushbutton with qpalette you have to do something like this:
QPalette palette = ui->pushButton->palette(); palette.setColor(QPalette::Button,Qt::green); ui->pushButton->setPalette(palette);
The result will be then similar to something like this:
If want change it to a custom color , you can use hex color code
palette.setColor(QPalette::Button,QColor("#FF0000")); // #FF0000 is for red color you can change it.
This should work for you,