我正在努力解决一个问题,我想它并不难,但我无法解决它。我对 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:{
}
}
}
}
}
}