focus - QML Keys weird / buggy behavior - event sent to the wrong object -


i experiencing weird behavior when handling qml keyboard events. in example, object tree can created, selecting tree element, plus , minus keys should append , remove elements of selected branch, , spacebar should expand or contract selected branch.

enter image description here

but doesn't work expected. while plus , minus work on active element, spacebar always expand/contract root element regardless of element selected. oddly enough, using mouse right button works on correct element expected, achieving desired behavior. both spacebar , right mouse button use practically same code, reason, using spacebar invokes function of root node, not on 1 in focus, should receiving keyboard events.

here relevant part of code:

ui {     id: ui     expanded: true      uilist {         model: ui.proxy.model()     }          rectangle {         width: 50         height: 50         color: ui.activefocus ? "red" : "darkred"         mousearea {             anchors.fill: parent             acceptedbuttons: qt.leftbutton | qt.rightbutton             onclicked: {                 if (mouse.button === qt.leftbutton) ui.forceactivefocus()                 else ui.expanded = !ui.expanded             }         }     }      keys.onpressed: {         switch (event.key) {         case qt.key_plus:             ui.create()             break         case qt.key_minus:             ui.pop()             break         case qt.key_space:             ui.expanded = !ui.expanded             break         }     } } 

so turns out forceactivefocus() gives focus not particular element, elements of hierarchy well. event received in target element , cascades down parents until root element.

a simple event.accepted = true in event handler suffices stop propagation down hierarchy.


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

mysql - FireDac error 314 - but DLLs are in program directory -