qt4 - Getting focus/activeFocus status from QML ListView -
i've 2 column layout listview in left column. left/right keys can change focus between 2 parts of app.
the active focus of left column delegated listview , there straight 1 of it's rows.
how can check whether listview or 1 of it's children has focus?
import qtquick 1.1 focusscope { width: 960 height: 540 id: app focus: true focusscope { id: leftcolumn keynavigation.right: rightcolumn anchors.bottom: parent.bottom anchors.left: parent.left anchors.top: parent.top width: 250 focus: true rectangle { id: leftbackgroundcolor anchors.fill: parent color: contactslist.activefocus ? "red" : "#e6e6e6" listview { id: contactslist interactive: true anchors.fill: parent focus: true delegate: text { text: name font.bold: activefocus } model: listmodel { listelement { name: "simon" } listelement { name: "mary" } listelement { name: "jack" } listelement { name: "frank" } } } } } focusscope { id: rightcolumn keynavigation.left: leftcolumn anchors.left: leftcolumn.right anchors.right: parent.right anchors.bottom: parent.bottom anchors.top: parent.top onfocuschanged: console.log("right focus changed: " + focus + "/" + activefocus) rectangle { id: rightbackgroundcolor anchors.fill: parent focus: true color: activefocus ? "red" : "#b3b3b3" } } }
i think found workaround:
onactivefocuschanged: { focuschanged(focus) }
this emits focuschanged signal whenever active focus changes. using this, property bindings (like color: parent.focus ? "red" : "#e6e6e6") work well.
full test code:
import qtquick 1.1 focusscope { width: 960 height: 540 id: app focus: true focusscope { id: leftcolumn keynavigation.right: rightcolumn anchors.bottom: parent.bottom anchors.left: parent.left anchors.top: parent.top width: 250 onactivefocuschanged: { focuschanged(focus) } rectangle { id: leftbackgroundcolor anchors.fill: parent color: parent.focus ? "red" : "#e6e6e6" listview { id: contactslist interactive: true anchors.fill: parent focus: true delegate: text { text: name font.bold: activefocus } model: listmodel { listelement { name: "simon" } listelement { name: "mary" } listelement { name: "jack" } listelement { name: "frank" } } } } } focusscope { id: rightcolumn focus: true keynavigation.left: leftcolumn anchors.left: leftcolumn.right anchors.right: parent.right anchors.bottom: parent.bottom anchors.top: parent.top onactivefocuschanged: { focuschanged(focus) } rectangle { id: rightbackgroundcolor anchors.fill: parent focus: true color: activefocus ? "red" : "#b3b3b3" } } }
Comments
Post a Comment