【发布时间】:2015-12-07 00:19:13
【问题描述】:
我正在尝试制作一个非常简单的程序来学习如何定义自定义 QML 类型以供重用。我不确定为什么会出现以下错误:
不能分配给不存在的属性“颜色”
我已经搜索了一个答案,但没有找到任何解决它的方法。
下面是代码。 Qt 用红色下划线color 和radius,表示它被标记为“无效的属性名称”。
//Button.qml
import QtQuick 2.3
Rectangle {
width: 100; height: 100
color: "red"
MouseArea {
anchors.fill: parent
onClicked: console.log("button clicked!")
}
}
//main.qml
import QtQuick 2.3
import QtQuick.Controls 1.2
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
menuBar: MenuBar {
Menu {
title: qsTr("File")
MenuItem {
text: qsTr("&Open")
onTriggered: console.log("Open action triggered");
}
MenuItem {
text: qsTr("Exit")
onTriggered: Qt.quit();
}
}
}
Column {
Button {width: 50; height: 50}
Button { x: 50; width: 100; height: 50; color: "blue" }
Button { width: 50; height: 50; radius: 8}
}
}
【问题讨论】: