0
shortcut = QtWidgets.QShortcut(QtGui.QKeySequence(QtCore.Qt.Key_Shift), MayaMainWindow)
shortcut.setContext(QtCore.Qt.ApplicationShortcut)

I have a system in place for overloading Maya shortcuts, as and when needed. I want to do this with the shift key, however simply writing it as above seems to do nothing. Not even an error message.

I have tried

QtGui.QKeySequence(QtCore.Qt.Key_Shift)
QtGui.QKeySequence(QtCore.Qt.Key_Shift + QtCore.Qt.SHIFT)
QtGui.QKeySequence(QtCore.Qt.Key_Shift + QtCore.Qt.NoModifier)
QtGui.QKeySequence(QtCore.Qt.Key_Shift + QtCore.Qt.NoButton)

I want to run a custom shortcut when only the shift key is pressed.

Adam Sirrelle
  • 357
  • 8
  • 18
  • 2
    From the [source code: qshortcutmap.cpp](https://code.woboq.org/qt5/qtbase/src/gui/kernel/qshortcutmap.cpp.html#_ZN12QShortcutMap9nextStateEP9QKeyEvent): "// Modifiers can NOT be shortcuts...". – ekhumoro Jun 08 '21 at 09:32
  • Sad times. If you put that as the answer, I'll set this as resolved. Thanks! – Adam Sirrelle Jun 09 '21 at 00:54
  • I've managed to hack something together with an event filter, which works for me as I don't need to overload this particular maya command (as it does nothing in the mode I am using). --def eventFilter(self, obj, event): --if self.use_shift_shortcut.isChecked(): --if event.type() == QtCore.QEvent.Type.KeyPress: --if event.key() == QtCore.Qt.Key_Shift: --# do stuff – Adam Sirrelle Jun 09 '21 at 01:59
  • Using an event-filter is not a hack. Trying to make QShortcut do things it wasn't designed for would be a hack. – ekhumoro Jun 09 '21 at 11:10

0 Answers0