Is there any method to define a variable in QSS file?
-
@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
cssvariable, 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) -
@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
cssvariable, 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)