Using two stylesheets for the same widget
-
I want to use a compilation variable in the .pro file. And then use it with #ifdef. The final purpose is: if I activate this variable, the application shows one color set and if I don't activate it, shows other color set.
-
Yes, I know how to configure a compilation variable, I need to know hoy to change the stylesheet of the application with this variable
-
Yes, but I want to know if it is possible to use this condition inside of the stylesheet in order to have only one stylesheet file
-
You can use custom properties set in your widgets to decide what stylesheet to apply:
https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-using-dynamic-properties -
You can use custom properties set in your widgets to decide what stylesheet to apply:
https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-using-dynamic-properties -
Hi,
Since you have your stylesheet in a file, use a placeholder for the colour and before your set the stylesheet replace the placeholder with the value matching what you want.
-
@VRonin Yes, I need something like that but for all widgets, like a "global" condition. Is it possible?
@ivanicy
I do just what @SGaist has just suggested.I don't like to maintain multiple files for different configurations, too much work. So to have stylesheets vary just by, say, color, I write one external stylesheet like
class1 { color: ##COLOR1##; } widget2 { background-color: ##COLOR2##; }in as many places as necessary. Then because you have to read the stylesheet in via code to apply it anyway, it's simple to substitute the various
##...##sequences for whatever you need while you're doing so.