summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnu Aliyas <anu.aliyas@qt.io>2024-02-19 13:57:45 +0100
committerMichael BrĂ¼ning <michael.bruning@qt.io>2024-04-09 20:14:34 +0200
commite227bbddbfc03c45735978f5b83994235225569a (patch)
tree98c887089064446faf3529587d1162e34bde7602
parent634192eee035308d1d44fa57757d6517d2a4efef (diff)
Retain focus while loading URLs into the page
While loading URLs, QtWebEngine will remove the old widget from the layout and then add the new widget. If the old widget is the focused widget, while deleting the widget, it will clear its focus, thereby causing QtWebEngine to lose focus. Therefore, if the old widget has focus, set focus to the new widget. Fixes: QTBUG-122153 Change-Id: I095a654ae80ad8089758eb785d4186a9708064a3 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io> (cherry picked from commit 0a8962b40de96ca87663938427a410ce65f3a8a2) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit ff9fd8806248973f6fdf92190f11b11af0319437) (cherry picked from commit d452147ca742ac77f22efd2aa1653a41baad88fe) Reviewed-by: Michal Klocek <michal.klocek@qt.io>
-rw-r--r--src/webenginewidgets/api/qwebengineview.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/webenginewidgets/api/qwebengineview.cpp b/src/webenginewidgets/api/qwebengineview.cpp
index c4a0da4d9..e804903fc 100644
--- a/src/webenginewidgets/api/qwebengineview.cpp
+++ b/src/webenginewidgets/api/qwebengineview.cpp
@@ -1,6 +1,7 @@
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+#include "qapplication.h"
#include "qwebenginenotificationpresenter_p.h"
#include "qwebengineview.h"
#include "qwebengineview_p.h"
@@ -441,6 +442,8 @@ void QWebEngineViewPrivate::widgetChanged(QtWebEngineCore::WebEngineQuickWidget
#endif
q->layout()->addWidget(newWidget);
q->setFocusProxy(newWidget);
+ if (oldWidget && oldWidget == QApplication::focusWidget())
+ newWidget->setFocus();
newWidget->show();
}
}