A few notes:
It is a good practice to get the palette from a widget, modify it, and set it back. Constructing a new palette object makes it use application's default palette which means losing any possible previous modifications to widget's palette:
palette.setColor(...);
widget->setPalette(palette);
QPalette palette = widget->palette();
palette.setColor(...);
widget->setPalette(palette);
To copy to clipboard, switch view to plain text mode
For a button, the correct color group is QPalette::Button:
palette.
setColor(QPalette::Button, Qt
::green);
button->setPalette(palette);
QPalette palette = button->palette();
palette.setColor(QPalette::Button, Qt::green);
button->setPalette(palette);
To copy to clipboard, switch view to plain text mode
QWindowsXpStyle and QMacStyle use native theming engines which cause some palette modifications not to have any effect. Certain colors/brushes/whatever come from the underlying system. Style sheets is the solution to this problem. Follow the link and see the example of changing QPushButton's color there.
Bookmarks