Qt Style Management and Execution

I have a problem managing Qt stylesheets.

I have a large Qt application that can dynamically change its color theme. For this I have created several stylesheets (one related - they are quite large). When the user wants to change the color theme, they click a button that calls the method QWidget

setStylesheet(QString)

MainWindow

. It does work, but my GUI freezes 8-10 seconds in the process.

To reduce the latency, I tried using unpolish(QApplication * application)

and QStyle::polish(QApplication * application)

. The efficiency is impressive (less than one second), but a few properties Widget

don't update, for example. icon property QToolButton

. In addition, all of my custom widgets are not updated, even if they are inherited from a common class of widgets ( QFrame

, QWidget

, QStackedWidget

etc.). Am I missing something with the method polish

? Is there any other way to improve my app's styling update?

0


source to share


1 answer


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 can be changed to suit the current GUI style in QStyle :: polish ().

Warning. Do not use this feature in conjunction with Qt stylesheets. When using style sheets, the widget's palette can be customized using "color", "background color", "highlight color", "selection-background-color" and "alternate-background-color".

Note. Some styles do not use a palette for the entire drawing, for example if they use their own theme engines.



If you want to change the theme of all widgets from one place, this is a good way.
I am using this in a large application and it works well.

But if you set a style or palette for a widget, it won't get your overall theme.

QPalette myPalette;
myPalette.setColor(QPalette::Background, Qt::red);
myPalette.setColor(QPalette::WindowText, QColor(150, 150, 150));
qApp->setPalette(myPalette);

      

0


source







All Articles