我正在尝试创建一个非常简单的程序来学习如何定义自定义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 …Run Code Online (Sandbox Code Playgroud)