PDA

View Full Version : How to declare variables in Qt Stylesheets



Asfer
24th February 2010, 13:14
Hi all,

Anybody knows if it is possible to create variables in a Qt Stylesheet (.qss)?

For instance, I know CSS accepts the following:



@variables {
myColour: #fe8d12;
}

div {
background-color: var(myColour);
}


I tried the same in qt (with QWidget instead of div) with no avail.

Any suggestions?
If it is not possible it would be a nice feature request.

BoberCoder
30th March 2012, 07:11
I want know to, how i can declare variables in Qt Stylesheets. So it's impossible ?

ChrisW67
30th March 2012, 07:36
... another zombie thread.

That ability is certainly not in the Qt Style Sheets docs. If you've tried it and it doesn't work then it doesn't work. You can, of course, dynamically create style sheets:


QString styleSheet(
"QLabel { background-color: %1; color: %2; }"
"QLineEdit { background-color: %1; }"
);
...
QString varBGColour("yellow");
QString varFGColour("steelblue");
setStyleSheet( styleSheet.arg(varBGColour).arg(varFGColour) );

I'd make sure it cannot be done with inheritance first.

BoberCoder
30th March 2012, 09:41
Yes, i know that i can dynamically create style sheets. But more better when you edit style sheet in designer, (not from code).