Qml小白求助 :-) 打擾大噶了哇
想實作一個功能,即點擊Button后,Button所對應的Image變為藍色,其余均為白色;當滑鼠移至Button上方時,若Image為藍色則不執行if陳述句所指定操作,否則變為灰色;當滑鼠離開Button時,若Image為藍色則不執行if陳述句所指定操作,否則變為白色。
但執行后,盡管Image為藍色,滑鼠移至Button上方或離開Button均會改變Image的顏色(即無視if條件的限制)。
以下為該功能相應代碼:
Button {
anchors.fill: parent
hoverEnabled: true
background: transparent
ToolTip.visible: hovered
ToolTip.text: qsTr("帶狀航線")
Image {
id: stripCourseImage
z: 5
width: stripCourseBtn.width * 0.4
height: stripCourseBtn.height * 0.4
mipmap: true
anchors.centerIn: parent
source: "Images/paper plane-fill white.svg"
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
onClicked: {
wayPointFlightImage.source = "Images/paper plane-fill white.svg"
aerialPhotographyImage.source = "Images/paper plane-fill white.svg"
obliquePhotographyImage.source = "Images/paper plane-fill white.svg"
stripCourseImage.source = "Images/paper plane-fill blue.svg"
}
onEntered: {
if(wayPointFlightImage.source != "Images/paper plane-fill blue.svg") {
wayPointFlightImage.source = "Images/paper plane-fill white.svg"
}
if(aerialPhotographyImage.source != "Images/paper plane-fill blue.svg") {
aerialPhotographyImage.source = "Images/paper plane-fill white.svg"
}
if(obliquePhotographyImage.source != "Images/paper plane-fill blue.svg") {
obliquePhotographyImage.source = "Images/paper plane-fill white.svg"
}
if(stripCourseImage.source != "Images/paper plane-fill blue.svg") {
stripCourseImage.source = "Images/paper plane-fill grey.svg"
}
}
onExited: {
if(stripCourseImage.source != "Images/paper plane-fill blue.svg") {
stripCourseImage.source = "Images/paper plane-fill white.svg"
}
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/188119.html
標籤:其他技術專區
上一篇:中臺起源及發展
下一篇:跪求一個matlab大神啊
