diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2020-04-28 11:31:11 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2020-05-05 23:03:26 +0200 |
commit | a8fee0bf431bb940da1684f59d0dee1e3ba5cede (patch) | |
tree | 6f9250f2babff87cd359a59e5b7e92d8bb25968d /src/widgets/kernel/qwidget.cpp | |
parent | 2f975b39a967cd2ac1c234a200eb6b9c11d8b5b2 (diff) |
Don't move focus away from previous proxy in QWidget::setFocusProxy
This amends 23b998fa454ca021aa595f66d2e1964da4a119a4, and the commits
3e7463411e549100eee7abe2a8fae16fd965f8f6 and
947883141d9d8b3079a8a21981ad8a5ce3c4798e. This change restores the
pre-5.13.1 behavior of setFocusProxy to not move focus away from a
previously set focus proxy.
With the previous changes, focus would move away from a proxy when a
new proxy is set, if the old proxy had focus. While there are arguments
in favor of this behavior, it is a change of behavior that shouldn't
be introduced to 20+ years old functionality in order to fix the real
bugs addressed by the initial commits.
Instead, move focus only to the new proxy when the focus widget was
the widget that gets a focus proxy.
[ChangeLog][QtWidgets][QWidget] setFocusProxy no longer moves focus
away from a previously set focus proxy, restoring pre-Qt 5.13.1
behavior.
Change-Id: Icf2ad7cba5b860014aeef91cb274c442a2ab9d42
Fixes: QTBUG-83720
Pick-to: 5.15
Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src/widgets/kernel/qwidget.cpp')
-rw-r--r-- | src/widgets/kernel/qwidget.cpp | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 6e3e9e0414..74ff3d744e 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -6176,7 +6176,8 @@ void QWidget::setWindowRole(const QString &role) setFocusProxy() sets the widget which will actually get focus when "this widget" gets it. If there is a focus proxy, setFocus() and - hasFocus() operate on the focus proxy. + hasFocus() operate on the focus proxy. If "this widget" is the focus + widget, then setFocusProxy() moves focus to the new focus proxy. \sa focusProxy() */ @@ -6194,16 +6195,12 @@ void QWidget::setFocusProxy(QWidget * w) } } - QWidget *oldDeepestFocusProxy = d->deepestFocusProxy(); - if (!oldDeepestFocusProxy) - oldDeepestFocusProxy = this; - - const bool focusProxyHadFocus = (QApplicationPrivate::focus_widget == oldDeepestFocusProxy); + const bool moveFocusToProxy = (QApplicationPrivate::focus_widget == this); d->createExtra(); d->extra->focus_proxy = w; - if (focusProxyHadFocus) + if (moveFocusToProxy) setFocus(Qt::OtherFocusReason); } |