Details
Description
I have a QWebEngineView and I used QWebEngineView::load() to load an URL. Then I call load() again to load a different URL. Immediately after the second call to load(), I call setFocus() on the view to give it focus. However, it seems that the call to setFocus() doesn't work, or at least it gives focus to a different widget than the view.
You can see this issue (which didn't happen in Qt5) with the attached program. It creates a main window with a line edit to enter an URL and a QWebEngineView to load it. Pressing return from the line edit loads the entered URL in the view and attempts to give focus to the view. The first time you enter the URL, giving focus to the view works correctly; however, doing the same a second time doesn't. You can easily see this loading https://www.google.com as second URL: you'll see the caret blinking in the search box, but trying to write something won't work.
I added a connection to QApplication::focusChanged to track what was happening. Here's the output:
//Pressing return the first time FOCUS CHANGED: OLD IS QLineEdit(0x55a67d411870) NOW IS QQuickWidget(0x55a67d05fd80) //Clicking on the line edit to enter second URL FOCUS CHANGED: OLD IS QQuickWidget(0x55a67d05fd80) NOW IS QLineEdit(0x55a67d411870) //Pressing return the second time FOCUS CHANGED: OLD IS QLineEdit(0x55a67d411870) NOW IS QQuickWidget(0x55a67d05fd80) FOCUS CHANGED: OLD IS QWidget(0x55a67d05fd80) NOW IS QWidget(0x0)
Comparing what happens in the first and the second case after pressing return, it seems that the second time the focus is switched from a QQuickWidget (which, I assume, is inside the view) to a null widget, while the first time this didn't happen.
I can work around this issue by calling setFocus() from a slot connected to the view's urlLoaded() signal (uncommenting line 23). However, I think this is a bug, since it didn't happen in Qt 5 (as can be seen with my example program by passing the -DBUILD_WITH_QT5=ON parameter to cmake. Note that you'll need to call make clean before switching from building with one to the other).