Propagate shortcuts — key inputs — from dialogs to Maya with Qt
If you want to use Maya or any other application’s shortcuts while you are using a custom tool, you need to propagate key events to the application. It can be useful with custom Qt dialogs and widgets.
To propagate a key event, you just need to ignore it in your widget or window.
class YourWidget(QtGui.QWidget):
....
def keyPressEvent(self, event):
if ... :
event.accept()
else:
event.ignore()
By default, the event is accepted, so accepting is useless. And don’t call the base class’s implementation after you ignore the event. Your actions will have no effect.
When you ignore an event, it will be transferred to the parent until a widget accepts it.
You can also disable keyboard focus on your widget.
self.setFocusPolicy(QtCore.Qt.ClickFocus) # or Qt.NoFocus
See setFocusPolicy and QKeyEvent for more details.