diff options
-rw-r--r-- | src/widgets/kernel/qapplication.cpp | 9 | ||||
-rw-r--r-- | tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp | 28 |
2 files changed, 37 insertions, 0 deletions
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index 42a1c0259d..f438f60e47 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -3326,6 +3326,15 @@ bool QApplication::notify(QObject *receiver, QEvent *e) { QWidget* w = static_cast<QWidget *>(receiver); QWheelEvent* wheel = static_cast<QWheelEvent*>(e); + + // QTBUG-40656, combo and other popups should close when the main window gets a wheel event. + while (QWidget *popup = QApplication::activePopupWidget()) { + if (w->window() != popup) + popup->close(); + else + break; + } + QPoint relpos = wheel->pos(); bool eventAccepted = wheel->isAccepted(); diff --git a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp index c38c254b9a..40496dbebb 100644 --- a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp +++ b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp @@ -53,6 +53,7 @@ #include <qdialog.h> #include <qevent.h> #include <qlineedit.h> +#include <qlabel.h> #include <qlistview.h> #include <qheaderview.h> #include <qlistwidget.h> @@ -131,6 +132,7 @@ private slots: void pixmapIcon(); void mouseWheel_data(); void mouseWheel(); + void wheelClosingPopup(); void layoutDirection(); void itemListPosition(); void separatorItem_data(); @@ -2041,6 +2043,32 @@ void tst_QComboBox::mouseWheel() } } +void tst_QComboBox::wheelClosingPopup() +{ + // QTBUG-40656, combo and other popups should close when the main window gets a wheel event. + QScrollArea scrollArea; + scrollArea.move(300, 300); + QWidget *widget = new QWidget; + scrollArea.setWidget(widget); + QVBoxLayout *layout = new QVBoxLayout(widget); + layout->setSizeConstraint(QLayout::SetMinAndMaxSize); + layout->addSpacing(100); + QComboBox *comboBox = new QComboBox; + comboBox->addItems(QStringList() << QStringLiteral("Won") << QStringLiteral("Too") + << QStringLiteral("3") << QStringLiteral("fore")); + layout->addWidget(comboBox); + layout->addSpacing(100); + const QPoint sizeP(scrollArea.width(), scrollArea.height()); + scrollArea.move(QGuiApplication::primaryScreen()->availableGeometry().center() - sizeP / 2); + scrollArea.show(); + QVERIFY(QTest::qWaitForWindowExposed(&scrollArea)); + comboBox->showPopup(); + QTRY_VERIFY(comboBox->view() && comboBox->view()->isVisible()); + QWheelEvent event(QPointF(10, 10), WHEEL_DELTA, Qt::NoButton, Qt::NoModifier); + QVERIFY(QCoreApplication::sendEvent(scrollArea.windowHandle(), &event)); + QTRY_VERIFY(!comboBox->view()->isVisible()); +} + void tst_QComboBox::layoutDirection() { QComboBox box; |