I can’t get single key shortcuts to work properly in PyQt on Mac. For example, if I change the QKeySequence below to Qt.Key_Tab it works fine, but Qt.Key_Control doesn’t work. Am I doing something wrong?
I’ve tried Qt.CTRL and "Ctrl" too, but they don’t work either.
shortcut = QShortcut(QKeySequence(Qt.Key_Control), self, self.show_dialog)
shortcut.setContext(Qt.ApplicationShortcut)
I’m unable to test this myself, but the modifiers map to different keys on a Mac: see the note at the end of the details section for
QKeySequence.It looks like you need to use Qt.Key_Meta.
Use this to see exactly which keys are being pressed:
EDIT
NB: Qt does not allow modifier keys (in any combination) to be set as shortcuts.