From 5c36926f6bc64e91153dcb7d3a5fd9543bf40b19 Mon Sep 17 00:00:00 2001 From: Michael Weghorn Date: Thu, 12 Dec 2024 08:39:33 +0100 Subject: [PATCH] QMenu: Accept accelerators typed on keypad Add Qt::KeypadModifier (and the combination with Qt::AltModifier) to the modifiers that may be set in a key event in order to trigger a menu action via its accelerator. Otherwise, an action that has a number set as the accelerator (e.g. using text "&1 Exit"), cannot be triggered by typing the corresponding number on the keypad. Fixes: QTBUG-73390 Change-Id: I0fa63b0c5f23823c61e159fcc72f7245215f8aae Reviewed-by: Axel Spoerl (cherry picked from commit ca4334bc966c7e5f9997f98b83afe37eb8b1d3ba) Reviewed-by: Qt Cherry-pick Bot (cherry picked from commit b5ba125fa07c71dfbd5ce0d62b946c232106f91b) --- src/widgets/widgets/qmenu.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index 5c4b60a8c6a..0d86d51357b 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -3363,8 +3363,11 @@ void QMenu::keyPressEvent(QKeyEvent *e) } if (!key_consumed) { // send to menu bar - if ((!e->modifiers() || e->modifiers() == Qt::AltModifier || e->modifiers() == Qt::ShiftModifier) && - e->text().size()==1) { + const Qt::KeyboardModifiers modifiers = e->modifiers(); + if ((!modifiers || modifiers == Qt::AltModifier || modifiers == Qt::ShiftModifier + || modifiers == Qt::KeypadModifier + || modifiers == (Qt::KeypadModifier | Qt::AltModifier)) + && e->text().size() == 1) { bool activateAction = false; QAction *nextAction = nullptr; if (style()->styleHint(QStyle::SH_Menu_KeyboardSearch, nullptr, this) && !e->modifiers()) {