QQuickComboBox: ensure we don't close popup on iOS

On iOS (and Android), we give focus to a control on touch release
(rather than on touch begin, which is normal on desktop). For a
QQuickCombobox, this means that we will both handle focus and open
the popup on touch release, and not focus on touch begin
and open popup on touch release, like on desktop. Because of this, we
need to be more careful about when we choose to close the popup as
well, otherwise it will close down before it gets a chance to show on iOS.

This patch will check why we lose focus on both the inner line edit
and the combobox itself, and based on this, choose whether we should
close the popup. Basically, if focus is just transferred between the
popup button and the line edit, we choose to keep the popup open.

Fixes: QTBUG-70161
Change-Id: Iec242c0b5570844868085480fdf96fc49d189b82
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
This commit is contained in:
Richard Moe Gustavsen 2019-03-15 15:05:22 +01:00
parent 27e030f24b
commit 5a07a970fa
1 changed files with 15 additions and 4 deletions

View File

@ -1556,8 +1556,13 @@ bool QQuickComboBox::eventFilter(QObject *object, QEvent *event)
break;
}
case QEvent::FocusOut:
if (qGuiApp->focusObject() != this) {
// Only close the popup if focus was transferred somewhere else
// than to the popup button (which normally means that the user
// clicked on the popup button to open it, not close it.
d->hidePopup(false);
setPressed(false);
}
break;
#if QT_CONFIG(im)
case QEvent::InputMethod:
@ -1583,9 +1588,15 @@ void QQuickComboBox::focusOutEvent(QFocusEvent *event)
{
Q_D(QQuickComboBox);
QQuickControl::focusOutEvent(event);
if (qGuiApp->focusObject() != d->contentItem) {
// Only close the popup if focus was transferred
// somewhere else than to the inner line edit (which is
// normally done from QQuickComboBox::focusInEvent).
d->hidePopup(false);
setPressed(false);
}
}
#if QT_CONFIG(im)
void QQuickComboBox::inputMethodEvent(QInputMethodEvent *event)