Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How do I check for Shift + Tab?
Forum Updated to NodeBB v4.3 + New Features

How do I check for Shift + Tab?

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 326 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.
  • J Offline
    J Offline
    johnzhou721
    wrote last edited by johnzhou721
    #1

    Should I use something like

    Qt::Key key = Qt::Key_Tab;
    Qt::KeyboardModifier modifier = Qt::ShiftModifier;
    QKeySequence seq(modifier | key);
    

    or should I do

    Qt::KeyboardModifier key = Qt::Key_BackTab;
    QKeySequence seq(key);
    

    Which of those is correct? Can someone explain the difference between ShiftModifier + Key_Tab vs BackTab in other contexts other than key modifiers as well? Which combination should I use in which contexts?

    Thanks.

    EDIT -- ANOTHER QUESTION

    Also another question -- what is Key_Any supposed to do? Is it literally any key? Since there;s no difference from it to Key_Space, does that mean I can't register the spacebar without registering all the other keys?

    EDIT 2 Also my other context is referring to when you assign shortcuts to a QAction.

    I 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote last edited by
      #2

      Hi,

      It's likely the same as Qt::Key_Copy that should match the key combination for copying on your platform (i.e. CMD+C on macOS and CTRL+C on the others).

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      I 1 Reply Last reply
      0
      • J johnzhou721

        Should I use something like

        Qt::Key key = Qt::Key_Tab;
        Qt::KeyboardModifier modifier = Qt::ShiftModifier;
        QKeySequence seq(modifier | key);
        

        or should I do

        Qt::KeyboardModifier key = Qt::Key_BackTab;
        QKeySequence seq(key);
        

        Which of those is correct? Can someone explain the difference between ShiftModifier + Key_Tab vs BackTab in other contexts other than key modifiers as well? Which combination should I use in which contexts?

        Thanks.

        EDIT -- ANOTHER QUESTION

        Also another question -- what is Key_Any supposed to do? Is it literally any key? Since there;s no difference from it to Key_Space, does that mean I can't register the spacebar without registering all the other keys?

        EDIT 2 Also my other context is referring to when you assign shortcuts to a QAction.

        I Online
        I Online
        IgKh
        wrote last edited by
        #3

        @johnzhou721 said in How do I check for Shift + Tab?:

        Which of those is correct? Can someone explain the difference between ShiftModifier + Key_Tab vs BackTab in other contexts other than key modifiers as well?

        Depending on what you are going to do with the QKeySequence? In general the Qt::Key_BackTab without modifier is the correct one to use, when matching the key sequence with a keyboard event directly or via a QShortcut.

        The context of the Key_BackTab appears to be that in ancient times (before my time for sure) some UNIX workstations had keyboards with separate right and left Tab keys (there is still a vague reminder of that in Unicode today, where there are still codepoints for ⇤ and ⇥, compared to the ↹ symbol that is probably printed on your keyboard's Tab key cap). Then for keyboards with a single bi-directional Tab key the X11 windowing system would intercept Shift+Tab and would send applications an event for a "Left Tab" press instead. To maintain consistency between platforms, I believe that Qt emulates that on Windows and macOS as well.

        1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          It's likely the same as Qt::Key_Copy that should match the key combination for copying on your platform (i.e. CMD+C on macOS and CTRL+C on the others).

          I Online
          I Online
          IgKh
          wrote last edited by
          #4

          @SGaist said in How do I check for Shift + Tab?:

          It's likely the same as Qt::Key_Copy that should match the key combination for copying on your platform

          Not quite, the layer that handles unifying different platform conventions for standard shortcuts is QKeySequence via the QKeySequence::StandardKey enum.

          I believe that the "Copy" key is for keyboards that actually had a dedicated Copy key, like those "Office Keyboards" that were all the rage like 10-15 years ago:

          keybaordfull-1013788122.jpg

          Haven't seen one of those in years though.

          1 Reply Last reply
          0
          • J Offline
            J Offline
            johnzhou721
            wrote last edited by
            #5

            So just to clarify:

            • Always use BackTab if you want to capture Shift + Tab (question: is that for specifically shift + tab?? What if you want to capture, say, Shift + Tab + Alt? Still use BackTab + Alt modifier?). Is this correct under the context of assigning a shortcut to a QAction?
            • Copy key is the specific Copy key that should only be used if you're specifically targeting those old MS Office keyboard, else use Ctrl+C sequence?

            Thank you!

            1 Reply Last reply
            0
            • J Offline
              J Offline
              johnzhou721
              wrote last edited by
              #6

              @IgKh see above post. Thanks!

              SGaistS 1 Reply Last reply
              0
              • J johnzhou721

                @IgKh see above post. Thanks!

                SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote last edited by
                #7

                @johnzhou721 No, the target age has nothing to do with BackTab or Copy (nor Cut and Paste).

                All these special values map to their platform specific sequences so you don't have to rewrite them in your code each time for each platform (i.e CTRL and CMD + "something").

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                J 1 Reply Last reply
                0
                • SGaistS SGaist

                  @johnzhou721 No, the target age has nothing to do with BackTab or Copy (nor Cut and Paste).

                  All these special values map to their platform specific sequences so you don't have to rewrite them in your code each time for each platform (i.e CTRL and CMD + "something").

                  J Offline
                  J Offline
                  johnzhou721
                  wrote last edited by
                  #8

                  @SGaist So only Shift + Tab have BackTab mapping, not Alt + Shift + Tab (i.e. Alt + Shift + Tab is not Alt + BackTab?) Also, besides BackTab, Copy, Paste, is there a list of such keys that are automatically mapped onto a single one? Thanks. I'm writing code where I have to map my application's cross-platform representations of the keys onto the Qt ones, and they're in the format of e.g. Shift + Tab instead of BackTab, Ctrl + C instead of Copy, etc... I only need to target KDE in this case, so I wonder if I just register shift + tab, ctrl + c etc for the shortcuts for the QAction it would suffice. Thanks!

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote last edited by
                    #9

                    It's not a mapping from multiple keys to one. These are just special values for that specific enum that will end up creating the sequence corresponding to the right platform specific version of the short-cut.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    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