Close popup widgets when wheel events are received
Task-number: QTBUG-40656 Change-Id: I134b07705744c23af9718dee486ab5e9ad4352cf Reviewed-by: Jørgen Lind <jorgen.lind@digia.com>
This commit is contained in:
parent
0475822d01
commit
92c7cb8155
@ -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();
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user