how to use the varieties in the qt stylesheet
-
once I founded someone use the stylesheet like this:
@define color_bg_list_msg #ff0000QWidget{
background-color:@color_bg_list_msg;
}In fact.the code above doesnt work for me.I wondered if there is the option to use the vars in the stylesheet.You know the css of the html offers the option what I mentioned.
-
once I founded someone use the stylesheet like this:
@define color_bg_list_msg #ff0000QWidget{
background-color:@color_bg_list_msg;
}In fact.the code above doesnt work for me.I wondered if there is the option to use the vars in the stylesheet.You know the css of the html offers the option what I mentioned.
@nicker-player
So far as I know Qt CSS/QSS (and for that matter same for full CSS in HTML) does not support any kind of "substitution" like this. If you found that in an example somewhere are you sure they did not implement the substitution in their code when reading in the CSS before setting the widget stylesheet from pre-processed code? I use something like your example with my own reading/substitution code if I need "dynamic" CSS/QSS content.You know the css of the html offers the option what I mentioned.
No, I don't think it does. Where is there a reference for HTML/CSS doing any such
@define
thing? (Seems CSS now has some Using CSS custom properties (variables) which I didn't know about. But it's still not the syntax you show and won't be in QSS anyway.) -
@nicker-player
So far as I know Qt CSS/QSS (and for that matter same for full CSS in HTML) does not support any kind of "substitution" like this. If you found that in an example somewhere are you sure they did not implement the substitution in their code when reading in the CSS before setting the widget stylesheet from pre-processed code? I use something like your example with my own reading/substitution code if I need "dynamic" CSS/QSS content.You know the css of the html offers the option what I mentioned.
No, I don't think it does. Where is there a reference for HTML/CSS doing any such
@define
thing? (Seems CSS now has some Using CSS custom properties (variables) which I didn't know about. But it's still not the syntax you show and won't be in QSS anyway.)@JonB said in how to use the varieties in the qt stylesheet:
No, I don't think it does. Where is there a reference for HTML/CSS doing any such @define thing? (Seems CSS now has some Using CSS custom properties (variables) which I didn't know about. But it's still not the syntax you show and won't be in QSS anyway.)
Indeed.
As the@
character is an unused symbol in C/C++ anyway, this code above isn't about C-languages.
I think the posted snippet was taken from some PHP/CSS example or something.
Python also knows@
but used in a different way.You can treat the Qt Stylesheet as string (
QString
) and then do this:QColor color(Qt::blue); QString style("QWidget{ background-color: %1; }").arg( color.name() ); // name = #RRGGBB QWidget w; w.setStyleSheet(style);