ShortcutOverride

From Qt Wiki
Revision as of 17:44, 14 January 2015 by Maintenance script (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Shortcut Override Events (QKeyEvent)

shortcut: a key combination that triggers an action
override: prevent the shortcut action under some circumstances

When the shortcut is about to trigger send shortcut override to the focus item instead. the focus item now has the option to override the shortcut (by accepting the shortcut override event).
If the shortcut override is accepted it will be delivered as normal key press to the focus widget. otherwise it will trigger the shortcut action.

Example: A media player uses space for pause/play. This should work everywhere except when searching for music in a line edit.

Example uses of ShortcutOverride in Qt:

QWidgetWindow::handleKeyEvent
QComboBoxPrivateContainer::eventFilter – for enter etc, bad implementation

QWidgetLineControl::processShortcutOverrideEvent(QKeyEvent *ke) – arrow keys, copy paste, …

QMainWindow::event – to show drag and drop cursor, doesn’t handle event otherwise

QMenu::event – override arrow and enter keys

QMenuBar::eventFilter – installs a global event filter (no, reallyFile:/) temporarily until next key press

Behavior:

In widgets the event is sent to the focus object and then to all it’s parent objects. Done by QGuiApplication::notify.

Implementation:

QWindowSystemInterface::tryHandleShortcutEvent return QGuiApplicationPrivate::instance()->shortcutMap.tryShortcutEvent(w, &qevent); only used on mac?

QShortcutMap::tryShortcutEvent(QObject *o, QKeyEvent *e) creates actual shortcut events returns true when shortcut should be overridden (not delivered and not trigger action), even before shortcut is complete results in QCoreApplication::sendEvent( shortcut overrid event)

Who may call try***ShortcutEvent? –

currently: QNSView: – (void)handleKeyEvent:(NSEvent *)nsevent eventType:(int)eventType m_sendKeyEvent = !QWindowSystemInterface::tryHandleShortcutEvent(focusWindow, timestamp, keyCode, modifiers, text); is the only user of the QWindowSystem one and thus the duplicate

QGuiApplication:

QApplication: