Details
-
Suggestion
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
5.15.13
-
None
Description
On macOS any shortcuts in the global menu of a main application window are working even when a tool window (e.g. undocked panel) has focus (this is due to the main menu being backed by native OS global menu). On Windows this won't work.
For my project I have modified the qShortcutContextMatcher to accept transient parent shortcuts for all tool windows, but probably it would be better to add a new Qt::WindowFlag that would control this behaviour. Below is my change to have the coherent behaviour (expected by my users) on all of the platforms:
--- a/src/controls/qquickaction.cpp +++ b/src/controls/qquickaction.cpp @@ -236,8 +236,18 @@ bool qShortcutContextMatcher(QObject *o, Qt::ShortcutContext context) if (QQuickItem * item = qobject_cast<QQuickItem*>(w)) w = item->window(); } - if (w && w == QGuiApplication::focusWindow()) + + auto focusWindow = QGuiApplication::focusWindow(); + + if (w && w == focusWindow) return true; + + // Tool windows that have focus should trigger shortcuts of their transient parents + if (w && focusWindow && + (focusWindow->flags() & Qt::Tool) == Qt::Tool && + focusWindow->transientParent() == w) { + return true; + } }