How do I check for Shift + Tab?
-
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 toKey_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.
-
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 andCTRL+C
on the others). -
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 toKey_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.
@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 theQt::Key_BackTab
without modifier is the correct one to use, when matching the key sequence with a keyboard event directly or via aQShortcut
.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. -
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 andCTRL+C
on the others).@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 theQKeySequence::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:
Haven't seen one of those in years though.
-
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!
-
@IgKh see above post. Thanks!
-
@IgKh see above post. Thanks!
@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").
-
@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").
@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!
-
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.