aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2/qquickpopup.cpp
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2017-07-10 16:48:07 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2017-07-11 09:41:13 +0000
commit744164e6c92cb721d2a339cee8c465e1685723f9 (patch)
tree680bf1ea6f68249a7985eb6a67780d0738d5c818 /src/quicktemplates2/qquickpopup.cpp
parentcc188f897af27daf47b0937e38ccb76ac2310abb (diff)
Fix focus handling for popups
When a popup is closed, if there are multiple popups open, restore focus to the next popup in chain instead of transferring focus to the window content. This allows us to cleanup the custom focus handling for sub-menus in dev. There is no more need to manually transfer focus to the parent menu or to a sub-menu, but calling open() or close() is enough and the focus is automatically transferred as expected. Change-Id: I54406c7c6b8dd25af261e00ebb1ae00ccbea8b9f Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quicktemplates2/qquickpopup.cpp')
-rw-r--r--src/quicktemplates2/qquickpopup.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/quicktemplates2/qquickpopup.cpp b/src/quicktemplates2/qquickpopup.cpp
index 8d533888..33b2ac1a 100644
--- a/src/quicktemplates2/qquickpopup.cpp
+++ b/src/quicktemplates2/qquickpopup.cpp
@@ -470,7 +470,13 @@ void QQuickPopupPrivate::finalizeExitTransition()
popupItem->setVisible(false);
if (hadActiveFocusBeforeExitTransition && window) {
- if (!qobject_cast<QQuickPopupItem *>(window->activeFocusItem())) {
+ // 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();
+ } else {
QQuickApplicationWindow *applicationWindow = qobject_cast<QQuickApplicationWindow*>(window);
if (applicationWindow)
applicationWindow->contentItem()->setFocus(true);