From e227bbddbfc03c45735978f5b83994235225569a Mon Sep 17 00:00:00 2001 From: Anu Aliyas Date: Mon, 19 Feb 2024 13:57:45 +0100 Subject: Retain focus while loading URLs into the page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Michael BrĂ¼ning (cherry picked from commit 0a8962b40de96ca87663938427a410ce65f3a8a2) Reviewed-by: Qt Cherry-pick Bot (cherry picked from commit ff9fd8806248973f6fdf92190f11b11af0319437) (cherry picked from commit d452147ca742ac77f22efd2aa1653a41baad88fe) Reviewed-by: Michal Klocek --- src/webenginewidgets/api/qwebengineview.cpp | 3 +++ 1 file changed, 3 insertions(+) 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(); } } -- cgit v1.2.3