From f9877da406ad96d82becb15b6eef9b723b8807e3 Mon Sep 17 00:00:00 2001 From: Wang Chuan Date: Sat, 16 Nov 2019 20:06:45 +0800 Subject: QQuickPopup: fix focus when multiple popup exiting When a focused Popup exited, it will try to transfer focus state to next Popup in chain or other item. However if there is an unfocused Popup exiting simultaneously, the focus state will be transferred to unfocused Popup, and this will cause loss of focus state since an unfocused Popup won't transfer its focus state to next Popup(or item) Fixes: QTBUG-79464 Change-Id: Ic06bd5a3616c8afbce449266e6fc24d2d54059d9 Reviewed-by: Mitch Curtis --- src/quicktemplates2/qquickpopup.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/quicktemplates2/qquickpopup.cpp b/src/quicktemplates2/qquickpopup.cpp index f272c5cf..45cbecf4 100644 --- a/src/quicktemplates2/qquickpopup.cpp +++ b/src/quicktemplates2/qquickpopup.cpp @@ -485,11 +485,18 @@ void QQuickPopupPrivate::finalizeExitTransition() if (hadActiveFocusBeforeExitTransition && window) { // restore focus to the next popup in chain, or to the window content if there are no other popups open - QQuickPopup *popup = nullptr; - if (QQuickOverlay *overlay = QQuickOverlay::overlay(window)) - popup = QQuickOverlayPrivate::get(overlay)->stackingOrderPopups().value(0); - if (popup && popup->hasFocus()) { - popup->forceActiveFocus(); + QQuickPopup *nextFocusPopup = nullptr; + if (QQuickOverlay *overlay = QQuickOverlay::overlay(window)) { + const auto stackingOrderPopups = QQuickOverlayPrivate::get(overlay)->stackingOrderPopups(); + for (auto popup : stackingOrderPopups) { + if (QQuickPopupPrivate::get(popup)->transitionState != ExitTransition) { + nextFocusPopup = popup; + break; + } + } + } + if (nextFocusPopup && nextFocusPopup->hasFocus()) { + nextFocusPopup->forceActiveFocus(); } else { QQuickApplicationWindow *applicationWindow = qobject_cast(window); if (applicationWindow) -- cgit v1.2.3