Unsolved Using two stylesheets for the same widget
-
-
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.