0

I have an issue with the management of Qt style sheets.

I have a big Qt application that can change its colors theme dynamically. To do that, I created several style sheets (one by theme - they are quite big). When a user wants to change the color theme, he clicks on a button that calls the QWidget method setStylesheet(QString) of the MainWindow. This actually works but my GUI freezes 8-10 seconds in the process.

To reduce the delay, I've tried to use unpolish(QApplication * application) and QStyle::polish(QApplication * application). The performance is quite impressive (less than one second) but several Widget properties are not updated, e.g. the icon property of the QToolButton. Moreover all my custom widgets are not updated even if they inherits from common widget classes (QFrame, Qwidget, QStackedWidget etc...). Do I miss something with the polish method? Is there another way to perform a better update of the style of my application?

ElGavilan
  • 6,610
  • 16
  • 27
  • 36
Al Jah
  • 1
  • 1

1 Answers1

0

You can use setPalette( QPalette )

void QApplication::setPalette ( const QPalette & palette, const char * className = 0 ) [static]

Changes the default application palette to palette.

The palette may be changed according to the current GUI style in QStyle::polish().

Warning: Do not use this function in conjunction with Qt Style Sheets. When using style sheets, the palette of a widget can be customized using the "color", "background-color", "selection-color", "selection-background-color" and "alternate-background-color".

Note: Some styles do not use the palette for all drawing, for instance, if they make use of native theme engines.

If you want to change theme of all widgets from one place, this is good way.
I use this in big application and it's working good.

But if you set styleSheet or palette to a widget, it is not getting your general theme.

QPalette myPalette;
myPalette.setColor(QPalette::Background, Qt::red);
myPalette.setColor(QPalette::WindowText, QColor(150, 150, 150));
qApp->setPalette(myPalette);
Ali Mofrad
  • 308
  • 5
  • 21
  • Yes, but this represents to much work. I am stuck with css files and I must use them. Thanks anyway. – Al Jah Dec 03 '14 at 16:22
  • @AlJah : You are right, when i switch from stylSheet to `QPalette`, it take more than one week from me . your welcome. – Ali Mofrad Dec 03 '14 at 16:31