summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets/qcombobox.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/widgets/qcombobox.cpp')
-rw-r--r--src/widgets/widgets/qcombobox.cpp44
1 files changed, 20 insertions, 24 deletions
diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp
index 9caac239f9..8a5ba769a8 100644
--- a/src/widgets/widgets/qcombobox.cpp
+++ b/src/widgets/widgets/qcombobox.cpp
@@ -58,7 +58,8 @@ QComboBoxPrivate::QComboBoxPrivate()
shownOnce(false),
duplicatesEnabled(false),
frame(true),
- inserting(false)
+ inserting(false),
+ hidingPopup(false)
{
}
@@ -735,8 +736,8 @@ bool QComboBoxPrivateContainer::eventFilter(QObject *o, QEvent *e)
return true;
default:
#if QT_CONFIG(shortcut)
- if (keyEvent->matches(QKeySequence::Cancel)) {
- combo->hidePopup();
+ if (keyEvent->matches(QKeySequence::Cancel) && isVisible()) {
+ keyEvent->accept();
return true;
}
#endif
@@ -2297,7 +2298,7 @@ void QComboBox::insertItems(int index, const QStringList &list)
if (list.isEmpty())
return;
index = qBound(0, index, count());
- int insertCount = qMin(d->maxCount - index, list.count());
+ int insertCount = qMin(d->maxCount - index, list.size());
if (insertCount <= 0)
return;
// For the common case where we are using the built in QStandardItemModel
@@ -2805,6 +2806,13 @@ void QComboBox::showPopup()
void QComboBox::hidePopup()
{
Q_D(QComboBox);
+ if (d->hidingPopup)
+ return;
+ d->hidingPopup = true;
+ // can't use QBoolBlocker on a bitfield
+ auto resetHidingPopup = qScopeGuard([d]{
+ d->hidingPopup = false;
+ });
if (d->container && d->container->isVisible()) {
#if QT_CONFIG(effects)
QSignalBlocker modelBlocker(d->model);
@@ -2829,30 +2837,11 @@ void QComboBox::hidePopup()
}
}
- // Fade out.
- bool needFade = style()->styleHint(QStyle::SH_Menu_FadeOutOnHide);
- bool didFade = false;
- if (needFade) {
-#if defined(Q_OS_MAC)
- QPlatformNativeInterface *platformNativeInterface = QGuiApplication::platformNativeInterface();
- int at = platformNativeInterface->metaObject()->indexOfMethod("fadeWindow()");
- if (at != -1) {
- QMetaMethod windowFade = platformNativeInterface->metaObject()->method(at);
- windowFade.invoke(platformNativeInterface, Q_ARG(QWindow *, d->container->windowHandle()));
- didFade = true;
- }
-
-#endif // Q_OS_MAC
- // Other platform implementations welcome :-)
- }
containerBlocker.unblock();
viewBlocker.unblock();
modelBlocker.unblock();
-
- if (!didFade)
#endif // QT_CONFIG(effects)
- // Fade should implicitly hide as well ;-)
- d->container->hide();
+ d->container->hide();
}
#ifdef QT_KEYPAD_NAVIGATION
if (QApplicationPrivate::keypadNavigationEnabled() && isEditable() && hasFocus())
@@ -3223,6 +3212,8 @@ void QComboBox::keyPressEvent(QKeyEvent *e)
return;
}
break;
+ case Qt::Key_Enter:
+ case Qt::Key_Return:
case Qt::Key_Escape:
if (!d->lineEdit)
e->ignore();
@@ -3243,6 +3234,11 @@ void QComboBox::keyPressEvent(QKeyEvent *e)
break;
#endif
default:
+ if (d->container && d->container->isVisible() && e->matches(QKeySequence::Cancel)) {
+ hidePopup();
+ e->accept();
+ }
+
if (!d->lineEdit) {
if (!e->text().isEmpty())
d->keyboardSearchString(e->text());