使用QCssParser解析css文件以定制窗口小部件 [英] Using QCssParser for parsing css file for custom widget

查看:837
本文介绍了使用QCssParser解析css文件以定制窗口小部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们假设我们有定制的小部件 RadioButton

Let's assume we have custom widget RadioButton :

RadioButton。

class RadioButton : public QAbstractButton
{
public:
    RadioButton();
};

和一个包含RadioButton规则的 CSS

And a CSS file that contain RadioButton rule:

Style.css

Style.css

RadioButton {
    color:#009688;
    font-size:12pt;
    opacity:0.5;
}

现在我要检索 RadioButton

一些搜索后,我发现了Qt私人cssparser:

After some searching i found Qt private cssparser :

a href =https://github.com/qt/qtbase/blob/dev/src/gui/text/qcssscanner.cpp =nofollow> qcssscanner.cpp

qcssscanner.cpp

qcssparser_p.h a>

qcssparser.cpp

现在我不知道如何使用这个解析器获取值(颜色值,...) / p>

And now i don't know how to use this parser to get values (color value,...)

int main() {
    QString css = "RadioButton {"
                    "color:#009688;"
                    "font-size:12pt;"
                    "opacity:0.5;"
                    "}";
    QCss::Parser parser(css);
}


推荐答案

example source

这是Qt的私有部分,因此请将这些文件您的项目中的本地项目:

This is private part of Qt so make these files local in your proj:

qcssscanner.cpp

qcssparser_p.h

qcssparser.cpp

这篇关于使用QCssParser解析css文件以定制窗口小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆