【发布时间】:2014-02-06 10:33:00
【问题描述】:
我想将组件的样式隔离在“ComponentStyle.qml”(Qt5)之类的文件中
ComponentSyle.qml
Item {
id:root
Component {
id: touchStyle
ButtonStyle {
....
}
}
Component {
id: switchStyle
SwitchStyle {
....
}
}
}
所以,在我的 main.qml 中,我想使用如下样式:
main.qml
...
Button {
style: touchStyle
text: "Press me"
width: parent.width
anchors.horizontalCenter: parent.horizontalCenter
}
但是,它不会工作!我有一些错误:
file:///C:/Qt/5.2.0/msvc2012/qml/QtQuick/Controls/Switch.qml:133: TypeError: 类型错误 file:///C:/Qt/5.2.0/msvc2012/qml/QtQuick/Controls/Button.qml:92:TypeError:无法读取 null 的属性“宽度”
main.qml:60: ReferenceError: touchStyle is not defined*
有人可以帮助我吗?非常感谢!
【问题讨论】: