summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorSona Kurazyan <sona.kurazyan@qt.io>2021-01-13 11:41:41 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-01-15 19:28:52 +0000
commitd96f00286cd570d70d9e8829e665a38928aefc20 (patch)
treebcd3cd0e7cf73aac39791c56c3a81e07fee9f168 /src/widgets
parenta24816ade4d18a3d04d5b0cca0f67b4c1eadbb2e (diff)
Fix setting active window as application's focus widget
When setting the application's focus widget we search for the next child widget that can hold the focus and call its setFocus() method, which also updates focus widgets of all its parent wigets. In case if the focus widget is the active window itself, we only set it as the application's focus widget, but we don't update the focus widget of the active window itself. Because of this the focusWidget() method always results nullptr for the active window. This prevents from setting the focus back to active window after the focus has changed (for example after a context menu is closed, as in the bugreport). Transfer the focus to active window by calling the setFocus() method, as it is done in case of transferring the focus to any other widget. Fixes: QTBUG-85846 Change-Id: I91ebf182fd5bb7d451a1186e2f3e38c8d48acc4e Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit 154573929a76d9051920756b19ed033c4b2ac649) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/kernel/qapplication.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp
index 63c3f9dd9b..b1341d1015 100644
--- a/src/widgets/kernel/qapplication.cpp
+++ b/src/widgets/kernel/qapplication.cpp
@@ -1869,12 +1869,13 @@ void QApplication::setActiveWindow(QWidget* act)
if (w) {
w->setFocus(Qt::ActiveWindowFocusReason);
} else {
- // If the focus widget is not in the activate_window, clear the focus
w = QApplicationPrivate::focus_widget;
- if (!w && QApplicationPrivate::active_window->focusPolicy() != Qt::NoFocus)
- QApplicationPrivate::setFocusWidget(QApplicationPrivate::active_window, Qt::ActiveWindowFocusReason);
- else if (!QApplicationPrivate::active_window->isAncestorOf(w))
+ if (!w && QApplicationPrivate::active_window->focusPolicy() != Qt::NoFocus) {
+ QApplicationPrivate::active_window->setFocus(Qt::ActiveWindowFocusReason);
+ } else if (!QApplicationPrivate::active_window->isAncestorOf(w)) {
+ // If the focus widget is not in the activate_window, clear the focus
QApplicationPrivate::setFocusWidget(nullptr, Qt::ActiveWindowFocusReason);
+ }
}
}
}