QCompleter: Hide popup when widget is hidden
When the widget the completer is attached to was hidden, the popup stayed open. It would "hang around" with no corresponding UI being around anymore, which is weird. Fixes: QTBUG-124861 Change-Id: If9cb04e693c2663ef9da14164611f26becafc4b4 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit 24859d7deaf995e992f0d9439a1c476126d5f654) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
5310cce3ce
commit
272808600a
@ -1296,10 +1296,21 @@ bool QCompleter::eventFilter(QObject *o, QEvent *e)
|
||||
{
|
||||
Q_D(QCompleter);
|
||||
|
||||
if (d->eatFocusOut && o == d->widget && e->type() == QEvent::FocusOut) {
|
||||
d->hiddenBecauseNoMatch = false;
|
||||
if (d->popup && d->popup->isVisible())
|
||||
return true;
|
||||
if (o == d->widget) {
|
||||
switch (e->type()) {
|
||||
case QEvent::FocusOut:
|
||||
if (d->eatFocusOut) {
|
||||
d->hiddenBecauseNoMatch = false;
|
||||
if (d->popup && d->popup->isVisible())
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case QEvent::Hide:
|
||||
if (d->popup)
|
||||
d->popup->hide();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (o != d->popup)
|
||||
|
@ -109,6 +109,8 @@ private slots:
|
||||
void dynamicSortOrder();
|
||||
void disabledItems();
|
||||
|
||||
void hideWidget();
|
||||
|
||||
// task-specific tests below me
|
||||
void task178797_activatedOnReturn();
|
||||
void task189564_omitNonSelectableItems();
|
||||
@ -1185,6 +1187,32 @@ void tst_QCompleter::disabledItems()
|
||||
QVERIFY(!view->isVisible());
|
||||
}
|
||||
|
||||
void tst_QCompleter::hideWidget()
|
||||
{
|
||||
// hiding the widget should hide/close the popup
|
||||
QWidget w;
|
||||
w.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
|
||||
w.setLayout(new QVBoxLayout);
|
||||
|
||||
QLineEdit edit;
|
||||
edit.setCompleter(new QCompleter({ "foo", "bar" }));
|
||||
|
||||
w.layout()->addWidget(&edit);
|
||||
|
||||
const auto pos = w.screen()->availableGeometry().topLeft() + QPoint(200, 200);
|
||||
w.move(pos);
|
||||
w.show();
|
||||
QApplicationPrivate::setActiveWindow(&w);
|
||||
QVERIFY(QTest::qWaitForWindowActive(&w));
|
||||
|
||||
// activate the completer
|
||||
QTest::keyClick(&edit, Qt::Key_F);
|
||||
QVERIFY(edit.completer()->popup());
|
||||
QTRY_VERIFY(edit.completer()->popup()->isVisible());
|
||||
edit.hide();
|
||||
QVERIFY(!edit.completer()->popup()->isVisible());
|
||||
}
|
||||
|
||||
void tst_QCompleter::task178797_activatedOnReturn()
|
||||
{
|
||||
if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive))
|
||||
|
Loading…
x
Reference in New Issue
Block a user