Qt QML: Keyboard and mouse does not work together to change the source image -
i struggling problem, guess not difficult not able solve it. experience qml small. appreciate help.
i have 3 radio buttons images. focus moves among radio buttons press keys , buttons highlighted. ( focus of radio button changes source images change radio button focus highlighted other image).
problem: when interact mouse (see source code) source (image) not change more…..no idea… while source changing before mouse interaction. checked in debugger source line never reached after mouse interaction.
i guess not right way change source image…please me solve or give me suggestion alternative
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:{ } } } } } }
please note using :
, , not assignment operator =
here -
source: focus ? "radiobutton_unselected_highlighted.png" : "radiobutton_unselected.png"
this means establishing binding, , not assigning fixed value property.
so if have
x : y
when want change property 'x', instead of changing property directly, change property 'y' on property 'x' depends, or binded with.
for case -
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: { rock.focus = true } onexited: { rock.focus = false } onclicked: { } } }
read qml property binding in detail.
Comments
Post a Comment