Unsolved Problem with button colors when changing palette.
-
When application palette is changed before a widget is shown all color roles are applied properly. But if you change app palette after showing the widget, the Button role color does not get updated. For instance in the following code color of push button remains unchanged:
#include <QApplication> #include <QPushButton> int main(int argc, char *argv[]) { QApplication a(argc, argv); qApp->setStyle("fusion"); QPalette palette; palette.setColor(QPalette::Button, Qt::black); QPushButton pb; pb.show(); for(int i=0;i<1000;i++) qApp->processEvents(QEventLoop::AllEvents); qApp->setPalette(palette); return a.exec(); }
I am using Qt 5.8. This was not the case in Qt 5.7. I have tested the code in Windows and Linux on different PCs, both have this problem. It seems that the problem is only for Button role and other roles are changed properly.
Is there any workaround to set a color for button role in the above example?
-
Please check Qt bug tracker - if it is not reported please file a bug report.
In your example code you are calling processEvents() before even loop is started (in exec()), so it might skew the results. Does it also not work when palette is changed after even loop is started?
-
@sierdzio I have reported this as a bug: https://bugreports.qt.io/browse/QTBUG-59101?filter=-2
The problem exists if palette is changed after starting event loop. Actually i have narrowed down the problem to show in a simple way when and how it occurs. I know it's a bug, I am looking for a workaround if possible.