Search code examples
qmlqt-quick

Using tab key for navigation in TextEdit


I have two TextEdit boxes and one custom button widget, I wish to change focus in the following order using the tab key on my keyboard:

TextEdit1 <-> TextEdit2 <-> Button

I have specified something similar to the following for each widget in order to obtain the chain above:

KeyNavigation.tab: TextEdit2
KeyNavigation.backtab: TextEdit1

My problem is however that the tab keystroke is caught in the TextEdit, and cannot be used to navigate. How can I disable tabs in the TextEdit and instead use it for changing focus?


Solution

  • I found the problem.

    By default the key events are first sent to the item which is receiving the event - not to KeyNavigation. This behavior can be changed by setting

    KeyNavigation.priority: KeyNavigation.BeforeItem
    

    The complete code thus becomes

    KeyNavigation.tab: TextEdit2
    KeyNavigation.backtab: TextEdit1
    KeyNavigation.priority: KeyNavigation.BeforeItem