How can I repaint my QPushButton
I'm using Qt5.5 to develop my program.
Here is part of my code
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?
Can u try with style sheet for your requirements?
We 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 .
Sorry, i can't see any thing in your example.
Could u post again?
Did you read the doc I posted?
A way by style sheet:
Yes, i assume that it means i have to change the code like this
I'm not quite sure so i want to see the example to evidence my hypothesis.
Am i right?
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,