--- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -724,9 +724,7 @@ case Qt::Key_Select: #endif if (view->currentIndex().isValid() && view->currentIndex().flags().testFlag(Qt::ItemIsEnabled)) { - combo->hidePopup(); keyEvent->accept(); - emit itemSelected(view->currentIndex()); } return true; case Qt::Key_Down: @@ -802,6 +800,28 @@ if (QGraphicsProxyWidget *proxy = graphicsProxyWidget()) proxy->hide(); #endif +} + +void QComboBoxPrivateContainer::keyPressEvent(QKeyEvent *e) +{ + switch (e->key()) { + case Qt::Key_Enter: + case Qt::Key_Return: +#ifdef QT_KEYPAD_NAVIGATION + case Qt::Key_Select: +#endif + if (isVisible() && view->currentIndex().isValid() && view->currentIndex().flags().testFlag(Qt::ItemIsEnabled)) { + e->accept(); + emit itemSelected(view->currentIndex()); + close(); + return; + } + break; + default: + break; + } + + QFrame::keyPressEvent(e); } void QComboBoxPrivateContainer::mousePressEvent(QMouseEvent *e) --- a/src/widgets/widgets/qcombobox_p.h +++ b/src/widgets/widgets/qcombobox_p.h @@ -206,6 +206,7 @@ protected: void changeEvent(QEvent *e) override; bool eventFilter(QObject *o, QEvent *e) override; + void keyPressEvent(QKeyEvent *e) override; void mousePressEvent(QMouseEvent *e) override; void mouseReleaseEvent(QMouseEvent *e) override; void showEvent(QShowEvent *e) override;