3
votes

I have an app that has Ctrl+S as a shortcut for the Save action in the file menu. This action has the default shortcut context of Qt::WindowShortcut.

In this app there's a docking window with an action that also uses the shortcut Ctrl+S. This shortcut has the context Qt::WidgetShortcut.

The window shortcut works fine. (It is executed if Ctrl+S is pressed when the focus is anywhere except the docking window I mentioned.)

The widget shortcut doesn't really work. That is, if the window action is disabled, then the widget one works, since there's no ambiguity. But if both actions are enabled, and the focus is on the docking window, then Ctrl+S does nothing.

It would seem to me that it wouldn't be unreasonable to expect that in the case of identical active shortcuts, then if one has more "local" context than the other, it would be the one to execute. I don't suppose there's any way to tell the Qt framework that that's what I want to happen? Or a general way to work around this? I could simply change one of the shortcuts so they aren't ambiguous, but these are localizable and platform-dependent so I can't guarantee that no other similar situation will arise.

1
Are you able to redirect the message that fires the widgetshortcut to the window you want ?Xavier V.
I'm not sure I follow you. The messages get received in the right places, it's just that the QShortcutEvent that ends up being generated has its "ambiguous" flag set, so when each QAction handles the event, it doesn't emit its "activated" signal.Owen

1 Answers

1
votes

I had a similar situation where two widgets had the same shortcut (for two different actions), but only one was being called. The only way I was able to fix this was to 1. remove the shortcuts from the actions in the two widgets 2. create another action with the shortcut in the parent window 3. call the appropriate widget handler from the window handler.