Qt 无法分配给不存在的属性
我试图制作一个非常简单的程序来学习如何定义自定义QML类型以供重用。我不确定为什么会出现以下错误: 无法分配给不存在的属性“颜色” 我一直在寻找答案,但没有找到任何解决方法 下面是代码。Qt在Qt 无法分配给不存在的属性,qt,qml,qtquick2,Qt,Qml,Qtquick2,我试图制作一个非常简单的程序来学习如何定义自定义QML类型以供重用。我不确定为什么会出现以下错误: 无法分配给不存在的属性“颜色” 我一直在寻找答案,但没有找到任何解决方法 下面是代码。Qt在color和radius下面加上红色下划线,表示它被标记为“无效属性名” Qt Quick Controls有一个按钮类型,您也有。显然,Qt快速控制导入的按钮(没有半径或颜色属性)是在本地文件上选择的。您有几个选择: 将您的按钮重命名为其他类型 将Qt快速控件导入命名空间 将类型导入命名空间 下面是您如何
color
和radius
下面加上红色下划线,表示它被标记为“无效属性名”
Qt Quick Controls有一个
按钮
类型,您也有。显然,Qt快速控制导入的按钮
(没有半径
或颜色
属性)是在本地文件上选择的。您有几个选择:
按钮重命名为其他类型
//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}
}
}
import QtQuick 2.3
import QtQuick.Controls 1.2 as Controls
Controls.ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
menuBar: Controls.MenuBar {
Controls.Menu {
title: qsTr("File")
Controls.MenuItem {
text: qsTr("&Open")
onTriggered: console.log("Open action triggered")
}
Controls.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
}
}
}