QAction
is dormant until you insert it somewhere. As vahancho has suggested, use QShortcut
. You need to instantiate the shortcut for each top-level widget (window) where you want it to be active. Thus if you have 5 top-level windows, you'll need 5 shortcuts, each having one of windows as its parent.
There is no way to use QShortcut
as a global shortcut without the gui. QShortcut
is only active when its associated widget has focus. The widget could be a top-level window.
System-global shortcuts are the subject of this question.