summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets/qcombobox.cpp
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2022-12-01 22:15:02 +0100
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2022-12-05 14:55:53 +0000
commita874087504cf5af8bb4171d4137f23f100b7063b (patch)
tree9d2bdb8b8a45c3cdf355749f01bddf75b6757747 /src/widgets/widgets/qcombobox.cpp
parent01412ff16ecf4a17fde7a49cbc8dacdc2a28da36 (diff)
QComboBox: hide the popup on keypress rather than ShortcutOverride
Qt sends a ShortcutOverride to the focus widget to evaluate whether the widget's key event handling has higher priority than shortcut handling. A KeyPress is then sent if the ShortcutOverride comes back accepted, or if the Shortcut event returns ignored. QComboBox needs to accept the ShortcutOverride for Cancel, so that hiding the popup has priority over application shortcuts. But it should only hide the popup when the KeyPress event actually arrives, as otherwise the the focus widget changes (from popup to combobox), which breaks event delivery on macOS. Fixes: QTBUG-108908 Pick-to: 6.4 6.4.2 Change-Id: Ie9cce1c2041cbe0e41be301686d7c3b5683e9f10 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/widgets/widgets/qcombobox.cpp')
-rw-r--r--src/widgets/widgets/qcombobox.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp
index 331764efa8..5889545b1c 100644
--- a/src/widgets/widgets/qcombobox.cpp
+++ b/src/widgets/widgets/qcombobox.cpp
@@ -728,7 +728,8 @@ bool QComboBoxPrivateContainer::eventFilter(QObject *o, QEvent *e)
default:
#if QT_CONFIG(shortcut)
if (keyEvent->matches(QKeySequence::Cancel)) {
- combo->hidePopup();
+ closeOnCancel = true;
+ keyEvent->accept();
return true;
}
#endif
@@ -775,6 +776,7 @@ bool QComboBoxPrivateContainer::eventFilter(QObject *o, QEvent *e)
void QComboBoxPrivateContainer::showEvent(QShowEvent *)
{
+ closeOnCancel = true;
combo->update();
}
@@ -3216,6 +3218,12 @@ void QComboBox::keyPressEvent(QKeyEvent *e)
break;
#endif
default:
+ if (e->matches(QKeySequence::Cancel) && (!d->container || d->container->closeOnCancel)) {
+ hidePopup();
+ e->accept();
+ d->container->closeOnCancel = false;
+ }
+
if (!d->lineEdit) {
if (!e->text().isEmpty())
d->keyboardSearchString(e->text());