Solved Is there any method to define a variable in QSS file?
-
As the topic, how to define a variable in qss.
just like #define FONT_SIZE 16px -
@brucezcg
Nope (nor in CSS) :( .You won't like this, but I have faced this problem. I do my work direct from Qt widgets, no QML/Qt Quick, so I don't know whether this is useful/applicable to you or not. I actually "pre-process" my QSS stylesheet file(s), before handing them off to
QtWidgets.QApplication.instance().setStyleSheet(css)
in code. So for example example my primary QSS file starts with:/* Set the base font size for all widgets */ * { font-size: <FONT_SIZE>pt; }
and my code, having read the file content into
css
variable, is like:# substitute all "<FONT_SIZE>" with the actual font size wanted fontSize = Settings.current().getDefaultFontSize() css = css.replace("<FONT_SIZE>", fontSize) biggerFontSize = Settings.current().getDefaultBiggerFontSize() css = css.replace("<BIGGER_FONT_SIZE>", biggerFontSize) ... QtWidgets.QApplication.instance().setStyleSheet(css)
-
@JonB Thanks, Let me try.