diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index 330bcb6a397..2f9e49426f5 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -737,7 +737,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 @@ -784,6 +785,7 @@ bool QComboBoxPrivateContainer::eventFilter(QObject *o, QEvent *e) void QComboBoxPrivateContainer::showEvent(QShowEvent *) { + closeOnCancel = true; combo->update(); } @@ -3234,6 +3236,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()); diff --git a/src/widgets/widgets/qcombobox_p.h b/src/widgets/widgets/qcombobox_p.h index a26f3a34d4c..d7b90bd2a72 100644 --- a/src/widgets/widgets/qcombobox_p.h +++ b/src/widgets/widgets/qcombobox_p.h @@ -221,6 +221,7 @@ private: QComboBoxPrivateScroller *bottom = nullptr; QElapsedTimer popupTimer; bool maybeIgnoreMouseButtonRelease = false; + bool closeOnCancel = false; friend class QComboBox; friend class QComboBoxPrivate;