【问题标题】:Qt Quick Controls Styles ReferenceErrorQt Quick Controls Styles ReferenceError
【发布时间】: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*

有人可以帮助我吗?非常感谢!

【问题讨论】:

    标签: qt qml


    【解决方案1】:

    不幸的是,我想我必须看到更多您的 ComponentStyle.qml,但我认为您缺少属性。

    您应该使用这两个链接来全面了解如何格式化主题和样式的代码。

    Styling - 在样式文本和按钮方面有很好的示例,非常适合您的情况。

    QmlStyling - 列出实现样式的不同方法和技术。

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 2017-09-11
      • 1970-01-01
      • 1970-01-01
      • 2017-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-18
      相关资源
      最近更新 更多