diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-02-10 16:49:38 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-02-12 12:33:36 +0000 |
commit | 598022cdc80f813000d6ccba16e33f876230b25e (patch) | |
tree | c22db85fe0a4384ef909e6fb775cbea88f89150d | |
parent | 51464de4a0575297aff049c345ba24b24b2a6fcb (diff) |
macOS: map Qt::Key_Return to NSCarriageReturnCharacter in menus
On macOS, key combinations with the Return key do not get delivered
through NSView::keyDown, but they are seen by the
QCocoaNSMenu::menuHasKeyEquivalent override. We already use that
override to check whether any menu item uses a matching shortcut, and
give Qt's focus object a chance to override the shortcut. The key
mapper used the NSNewlineCharacter '\n' for Qt::Key_Return.
However, the character we get from macOS for the return key is the
NSCarriageReturnCharacter character, '\r'. This makes the lookup
fail, and shortcut overrides are not delivered for shortcuts using
Qt::Key_Return.
To fix this, map Qt::Key_Return to NSCarriageReturnCharacter. The
inverse mapping maps both NSCarriageReturnCharacter and
NSNewlineCharacter to Qt::Key_Return, and there are no other users
of this function in Qt.
Fixes: QTBUG-107526
Change-Id: I716190adf3cd94697e2b3ad1afc25b95d8ebde25
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
(cherry picked from commit 0835537c3c3a8b7991b7a6e4a877a13f165a66e7)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/gui/platform/darwin/qapplekeymapper.mm | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/gui/platform/darwin/qapplekeymapper.mm b/src/gui/platform/darwin/qapplekeymapper.mm index 2b0335fef4..59cdc4f869 100644 --- a/src/gui/platform/darwin/qapplekeymapper.mm +++ b/src/gui/platform/darwin/qapplekeymapper.mm @@ -360,7 +360,7 @@ QChar QAppleKeyMapper::toCocoaKey(Qt::Key key) { // Prioritize overloaded keys if (key == Qt::Key_Return) - return QChar(NSNewlineCharacter); + return QChar(NSCarriageReturnCharacter); if (key == Qt::Key_Backspace) return QChar(NSBackspaceCharacter); |