0
我正在努力解決問題,我猜它不是那麼難,但我無法解決它。我對QML的體驗非常小。我會感謝你的幫助。Qt QML:鍵盤和鼠標不能一起改變源圖像
我有三個單選按鈕作爲圖像。當按下按鍵時,焦點在單選按鈕之間移動,因此按鈕突出顯示。 (由於單選按鈕的焦點更改,源圖像也會更改,因此帶有焦點的單選按鈕將與其他圖像一起高亮顯示)。
問題:當我與鼠標交互時(見源代碼),源代碼(圖像)不再改變...... ..不知道......在鼠標交互之前源發生變化。我在調試器中檢查了鼠標交互後永遠不會到達源代碼行。
我想它不是正確的方式更改爲源圖像......請幫我解決這個問題或者給我一個建議的替代
Rectangle { //main container
id: rectangle1
x: 0
y: 0
width: 480
height: 620
color: "#ffffff"
Item { // focus scope container
id: focus_object
focus : true
Image { // radio button 1
id: rock
x: 5
y: 6
fillMode: Image.PreserveAspectFit
smooth: true
focus:true
source: focus ? "Radiobutton_unselected_highlighted.png" : "Radiobutton_unselected.png"
KeyNavigation.right: pop
MouseArea {
anchors.fill: parent
hoverEnabled: true
onEntered: {
parent.source = "Radiobutton_unselected_highlighted.png"
}
onExited: {
parent.source = "Radiobutton_unselected.png"
}
onClicked:{
}
}
}
Image { // radio button 2
id: pop
x: 160
y: 6
width: 64
height: 64
fillMode: Image.PreserveAspectFit
smooth: true
source: focus ? "Radiobutton_unselected_highlighted.png" : "Radiobutton_unselected.png"
KeyNavigation.left: rock
KeyNavigation.right: classic
MouseArea {
anchors.fill: parent
hoverEnabled: true
onEntered: {
parent.source = "Radiobutton_unselected_highlighted.png"
}
onExited: {
parent.source = "Radiobutton_unselected.png"
}
onClicked:{
}
}
Image { // radio button 3
id: classic
x: 306
y: 6
width: 64
height: 64
fillMode: Image.PreserveAspectFit
smooth: true
source : focus ? "Radiobutton_unselected_highlighted.png" : "Radiobutton_unselected.png"
KeyNavigation.left: pop
MouseArea {
anchors.fill: parent
hoverEnabled: true
onEntered: {
if (true == focus)
parent.source = "Radiobutton_unselected_highlighted.png"
}
onExited: {
parent.source = "Radiobutton_unselected.png"
}
onClicked:{
}
}
}
}
}
}