Unsolved Using two stylesheets for the same widget
-
Hello!! I need to have two versions of the same software. This versions change their colors so, I need to know if is it possible to give some condition to load the correct stylesheet.
How can I do that?
Thank you very much!
-
@ivanicy said in Using two stylesheets for the same widget:
some condition
What condition would it be?
If you build different versions of your software you can decide at compile time what to use.
You you check the condition at runtime and load the stylesheet accordingly. -
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
-
@ivanicy You already wrote how:
#ifdef SOME_VARIABLE // Load stylesheet a #else // Load stylesheet b #endif
Or wat exactly is the question?
-
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
-
@ivanicy It's not. But you could modify the stylesheet depending on that condition before loading it.
-
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 -
This post is deleted! -
@VRonin Yes, I need something like that but for all widgets, like a "global" condition. Is it possible?
-
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.
-
@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.