Sending key shortcuts to active window
-
Hello guys, I do wonder, what's the best way to send shortcuts to active window? I do have menuBar which emits slots in my "shortcut dispatcher" object. Now I do wonder, how to push forward those messages forward? Hook up focusEvent and cast QWidget to my own Window subclass?
-
Why do you "dispatch shortcuts" yourself? Qt has a built in mechanism for shortcuts and scoping.
If you have a QShortcut with a certain widget parent or a QAction with shortcut added to that widget and you set the context toQt::WidgetWithChildrenShortcut
it will be scoped properly without you doing anything more. -
I'm not sure I understand. If you have shortcut
shA
with parent windowA
and shortcutshB
with parent windowB
and both shortcuts have aQt::WidgetWithChildrenShortcut
scope then they work in their respective windows. The windows don't need a common parent for shortcuts to work. -
Well, I have a custom shortcut
shC
applied to Action/Menu which is global (in every window), but I can not register that into window A, or window B. I mean, I am on OS X, where there is only one menubar that is shared across the multiple windows, so I have to dispatch them, right?I mean, for example, Qt Creator has a shortcut "Run" which is invokable from many windows. But I can not make two menubars and/or having two actions, right?