Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-122153

QWebEngineView::setFocus() doesn't give focus to the view after calling QWebEngineView::load() for the second time

    XMLWordPrintable

Details

    • Linux/X11
    • 0a8962b40 (dev), ff9fd8806 (6.7), d452147ca (6.6), e227bbddb (6.5), c12852b32 (tqtc/lts-6.5)

    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).

      Attachments

        1. main.cpp
          2 kB
          Stefano Crocco
        2. CMakeLists.txt
          0.5 kB
          Stefano Crocco
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt_webengine_team Qt WebEngine Team
            stefano.crocco Stefano Crocco
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes