Force focus to TextEdit in ListView -


consider following example.

rectangle {     height: 200     width: 200     listview {         id: lv         anchors.fill: parent         model: listmodel {             listelement {                 name: "aaa"             }             listelement {                 name: "bbb"             }             listelement {                 name: "ccc"             }         }         delegate: textedit {             id: delegate             text: name             width: 200             height: 100             activefocusonpress: false             onactivefocuschanged: {                 if(activefocus) {                     font.italic = true;                 } else {                     font.italic = false;                 }             }             mousearea {                 anchors.fill: parent                 ondoubleclicked : {                     delegate.focus = true;                     lv.currentindex = index;                 }             }         }     } } 

i able activate textedit double click. if it's outside of list view works expected, in list view doe's not work. guess problem list view focus scope, don't know how fix it.

thanks in advance.

you can exploit forceactivefocus:

this method sets focus on item , ensures ancestor focusscope objects in object hierarchy are given focus.

you can either use overloaded version (without parameters) or 1 focusreason. here modified version of code using latter. i've made 2 small adjustments explanatory comment:

import qtquick 2.4 import qtquick.window 2.2  window {     visible: true     width: 200     height: 200      listview {         anchors.fill: parent         model: listmodel {             listelement {                 name: "aaa"             }             listelement {                 name: "bbb"             }             listelement {                 name: "ccc"             }         }         delegate: textedit {             text: name             // in delegate can access listview via "listview.view"             width: listview.view.width               height: 50             activefocusonpress: false             // directly bind property 2 properties (also saving brackets)             onactivefocuschanged: font.italic = activefocus              mousearea {                 anchors.fill: parent                 ondoubleclicked : {                     parent.forceactivefocus(qt.mousefocusreason)                     parent.listview.view.currentindex = index                 }             }         }     } } 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -