Passing control+keypress instructions from one form to another
-
In my PyQt5 application, I've got two
QDialog
windows open, and the first one has aQMenuBar
with various options. Some of these have keyboard shortcuts, e.g. Ctrl+S for Save, Ctrl+F for Find etc.If the user presses Ctrl+S or Ctrl+F while the other dialog has focus, is there any way of passing this to the first dialog, so that the save or find functions are triggered?
I have tried doing this with passing the parameter of
keyPressEvent()
from the second form tokeyPressEvent()
on the first form, but this only seems to pass individual key values, not Ctrl+key combinations etc., so the first form gets "Ctrl" and then "S" but never a "Ctrl+S" trigger.Is there a way I could pass these key combination triggers to the first form, without having to code each one individually for the second form? (There are quite a few of them.)
-
Set the shortcuts' context to
Qt::ApplicationShortcut
.
https://doc.qt.io/qt-5/qt.html#ShortcutContext-enum -
Exactly what I needed, works immediately. Thanks very much!
-
@donquibeats said in Passing control+keypress instructions from one form to another:
works immediately.
great, so don't forget to mark your post as solved then!