Qt still does not support CSS variables :( aaargh!!
-
Hi
Yes, CSS2 Variables would be nice for an easy way to manage settings.Depending on your actual use case / what you need, some sort of text processing is needed.
Qstrings ARG function can be used
https://doc.qt.io/qt-5/qstring.html#arg
for smaller variable substitutionHowever, for more complex replacement, you might want to create a small parser to do the job.
But it depends on what you needed the vars for. Mine was for colors so I had a lookup table I used
to set the actual colors from a .ini file. -
@Kris-Revi
As @mrjj says, you end up needing to "pre-process" some CSS text you write with some kind of "substitution" for your desired variable part.I write an external CSS file like usual and put something like
{ background-color: #background-color-1#; font: #font-2#; }
wherever into it. At runtime you read it in, do whatever
#...#
substitutions and then apply the resulting CSS text to the application or widgets. -
@Kris-Revi
Ok :)
well Style sheet allows multiline comments so you could embed all the tags in top of the file/* color_top=RGB(0,0,0) left_margin=4 */ ... stylesheet..
Then at start up read the file and extract the tags to std::map and use that to replace in the rest of the file.
I would also make a function that scans the file and output a file with all found Tags so it's easy to
update the "header" and allows you to invent tags on the fly so to speak.