Qt Creator 3.1.2基于Qt 5.3.1(MSVC 2010,32位).Project具有导入QmlProject 2.0 这是我的程序,我有这个错误。这个程序来自教程,它对他有用。所以我不确定那里的问题是什么。
import QtQuick 2.0
Rectangle {
id: rootTangle
width: 360
height: 360
color: "red"
hoverEnabled: true;
Rectangle {
id: blueRec
color: "blue"
//opacity: .50
width: rootTangle.width/2
height: rootTangle.width/6
anchors.centerIn: rootTangle
border.color: "black"
border.width: 7
rotation: 180
radius: 20
gradient: Gradient {
GradientStop { position: 0.0; color: "#b0c5de" }
GradientStop { position: 1.0; color: "blue" }
}
}
Text {
id: nazdarTxt
anchors.centerIn: blueRec
text: "Nazdar"
clip: false
visible: true
font.family: "Times New Roman"
font.bold: true
//font.pixelSize: Math.round(blueRec.height/3)
width: blueRec.width
//wrapMode: Text.WordWrap
}
MouseArea {
id: blueRecMouseArea
hoverEnabled: true;
onEntered: {
blueRec.color: "brown"
}
anchors.rightMargin: 0
anchors.bottomMargin: 0
anchors.leftMargin: 1
anchors.topMargin: 0
anchors.fill: blueRec
onClicked: {
Qt.quit();
}
}
}
错误在第46行:onEntered: {
blueRec.color: "brown"
}
答案 0 :(得分:5)
问题是颜色后的冒号:
onEntered: {
blueRec.color: "brown"
}
你应该改为等号:
onEntered: {
blueRec.color = "brown"
}
此外,Rectangle中没有 hoverEnabled ,因此您需要删除或评论它:
Rectangle {
id: rootTangle
width: 360
height: 360
color: "red"
//hoverEnabled: true;
由于您已经为 blueRec 定义了渐变,因此更改其颜色无效,您应该更改渐变颜色:
onEntered: {
blueRec.gradient.stops[0].color = "brown"
blueRec.gradient.stops[1].color = "white"
}