Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML how to call Shift+Tab behavior without using keyboard?
Forum Updated to NodeBB v4.3 + New Features

QML how to call Shift+Tab behavior without using keyboard?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 255 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kuba-dev
    wrote on last edited by
    #1

    I have an embedded linux device with only 5 keys mapped in system as keyboard emiting keyboard events:
    1 - TAB
    2 - SPACE
    3 - UP
    4 - DOWN
    5 - ESC
    It is enough to edit parameters - many SpinBoxes with focus change with TAB. But the client wants to have an option to focus back just like on desktop by pressing Shift + Tab, but by pressing SPACE on Spinbox
    How to do that in QML?

    Got something like:

        function navBack(repeater,model)
        {
            let prevItem = repeater.itemAt(model.index-1)
            if(prevItem)
                prevItem.forceActiveFocus()
        }
    
                   SpinBox {
                        Keys.onSpacePressed: {
                            navBack(repeater,model);
                            event.accepted = true
                        }
    
    

    And it works inside repeater, but I am unable to focus Back previous editable element like by pressing Shift+TAB
    Which function is called on Shift+TAB key combination? And how to call it?

    1 Reply Last reply
    1
    • GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by GrecKo
      #2

      Item has a nextItemInFocusChain(bool forward = true) function.

      You could do

      Keys.onSpacePressed: event => {
          const previousItem = nextItemInFocusChain(false);
          if (previousItem)
              previousItem.forceActiveFocus();
          event.accepted = true;
      }
      

      EDIT: that could also be done at the window level with a shortcut or an event filter to not have to modify each item.

      1 Reply Last reply
      1
      • K Offline
        K Offline
        Kuba-dev
        wrote on last edited by
        #3

        It worked perfectly! Thank you

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved