Using Qt private CSS parser
-
You would have to enable the use of the private parts of Qt with all the big fat warnings that comes with it.
I already compile it (and also disable warnings) :
int main() { QString css = "RadioButton {" "color:#009688;" "font-size:12pt;" "opacity:0.5;" "}"; QCss::Parser parser(css); }
But at this time i want to get the color value (#009688) of
RadioButton
but the source code of this parser is complicated (may be i should make the parse tree)Why do you want to parse your css since you already know what's in it ?
Because i want to read an external
CSS
file and get my app's widgets properties from it.
For example : in myRadioButton
painting i use an opacity value and when i change the opacity fromCSS
file allRadioButton
must be change to new opacity. -
Then why not just set that external style sheet directly ?
-
@SGaist
Well.
We assigned stylesheet :class RadioButton : public QAbstractButton { public: RadioButton() { QString css = "RadioButton {" "color:#009688;" "font-size:12pt;" "opacity:0.5;" "}"; setStyleSheet(css); } };
But the problem is accessing the values So how we should get opacity :
QPainter::setOpacity(/* required opacity */);
-
Isn't the windowOpacity property holding that?
-
Are you doing all the painting yourself ?
-
What attributes are you going to support ?
-
@IMAN4K said:
Now i'm going to retrieve RadioButton's properties from Style.css
for that after some searching i found Qt private CSS scanner and parser :
qcssscanner.cpp
qcssparser_p.h
qcssparser.cppAnd now i don't know how to use this parser to get token types + values
Hi.
Something like this... Not recommended...
#include <QtGui/5.7.0/QtGui/private/qcssparser_p.h> [...] QCss::Parser parser(yourStyleSheetString); while (parser.testSelector()) { QCss::StyleRule styleRule; if (parser.parseRuleset(&styleRule)) { foreach (auto sel, styleRule.selectors) { foreach (auto bSel, sel.basicSelectors) { qDebug() << "BasicSelector:" << bSel.elementName; } } foreach (auto decl, styleRule.declarations) { qDebug() << "property:" << decl.d->property; foreach (auto value, decl.d->values) { qDebug() << "value:" << value.variant; } } } } [...]