From 92c7cb815522ad1b31e98cc1e7adeabde58057da Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 26 Aug 2014 15:46:48 +0200 Subject: [PATCH] Close popup widgets when wheel events are received MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-number: QTBUG-40656 Change-Id: I134b07705744c23af9718dee486ab5e9ad4352cf Reviewed-by: Jørgen Lind --- src/widgets/kernel/qapplication.cpp | 9 ++++++ .../widgets/qcombobox/tst_qcombobox.cpp | 28 +++++++++++++++++++ 2 files changed, 37 insertions(+) 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(receiver); QWheelEvent* wheel = static_cast(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 #include #include +#include #include #include #include @@ -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;