【发布时间】:2014-11-09 03:31:41
【问题描述】:
我知道 QML 不像小部件那样支持 CSS 样式,并且我已经阅读了样式/主题的替代方法:
- https://qt-project.org/wiki/QmlStyling
- http://www.slideshare.net/BurkhardStubert/practical-qml-key-navigation/34
这些方法的共同点是,它们要求开发人员指定可以设置样式的 QML 部分,方法是绑定到“样式化 QML 文件/单例”中的属性,或者使用加载器加载不同的基于样式名称的 QML 组件。我想要的是类似于 CSS 中的“id”选择器而不是“class”选择器的东西,这样各个 QML 文件就不必知道它们以后是否会被设置样式。
我当前的方法使所有 QML 文件看起来都类似于此(使用链接 2 中的方法):
Main.qml
Rectangle {
Id: background
color: g_theme.background.color
//g_theme is defined in root context and loaded dynamically
}
我想做的是:
Main.qml
Rectangle {
Id: background
color: “green” // default color
}
然后有一个样式文件定义(或类似)
Main.qml #background.color: red
目前是否有可能,或者正在为未来的 Qt 版本准备中,或者首选的样式设置方式是否会继续类似于上面链接中描述的方法?
【问题讨论】: