summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qshortcut_p.h
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2023-09-29 17:45:49 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2023-10-11 20:32:05 +0200
commitcd4000a97d325029acab7c253c1774c01ad6f782 (patch)
treec2a9e2cc9d8c7fe0bf73493cd16aebed2323d4cb /src/gui/kernel/qshortcut_p.h
parent7d3417fbfcbfc46061609a842768a0111c5a15a2 (diff)
Use QtGui to match QWindow based shortcuts, even when QApplication is used
If a QShortcut is registered with a QWindow as its parent, but QApplication is used, we end up in QApplicationPrivate::createShortcutPrivate(), and create a QtWidgetsShortcutPrivate that implements shortcut context matching via qWidgetShortcutContextMatcher. The problem is that qWidgetShortcutContextMatcher expects the windows to be QWidgetWindows, which meant that plain QWindow based shortcuts would always fail. This can happen for example if a QApplication is used in Qt Quick to provide dialog fallbacks, but QShortcuts are otherwise used with plain QWindows, or QQuickWindows e.g. We now defer the check of whether there's an active (widget) window, and fall back to QtGui's simpleContextMatcher in case we don't find a QWidget, QAction, or QGraphicsWidget shortcut owner to handle the matching for. Note: We don't support shortcut matching for QAction in QtGui, but this is left for another day. There is also a discrepancy between how QtGui and QtWidgets handles Qt::ApplicationShortcut. The former will treat it as a match even if there is no active QWindow, while the latter requires that there's an active widget window. Fixes: QTBUG-116221 Change-Id: I487995f2e660a40f6556828b84a521d81a58f1b6 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/gui/kernel/qshortcut_p.h')
-rw-r--r--src/gui/kernel/qshortcut_p.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/gui/kernel/qshortcut_p.h b/src/gui/kernel/qshortcut_p.h
index a99cca27c1..8ff833d477 100644
--- a/src/gui/kernel/qshortcut_p.h
+++ b/src/gui/kernel/qshortcut_p.h
@@ -43,6 +43,8 @@ public:
virtual QShortcutMap::ContextMatcher contextMatcher() const;
virtual bool handleWhatsThis() { return false; }
+ static bool simpleContextMatcher(QObject *object, Qt::ShortcutContext context);
+
QList<QKeySequence> sc_sequences;
QString sc_whatsthis;
Qt::ShortcutContext sc_context = Qt::WindowShortcut;