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

When calling QWebEngineView::setFocus after calling QWebEngineView::setFocus for the second time, focus is given to another widget

    XMLWordPrintable

Details

    • Linux/X11
    • c8f8749e8 (dev), 4942d3cee (6.9), 6da5aeb5d (6.8)

    Description

      This is similar bug QTBUG-122153, which I reported last year and was fixed in Qt 6.6.3. If I do the following:

      • call `QWebEngineView::load()` with an URL
      • call `QWebEngineView::load()` with another URL (after waiting the first page to load)
      • call `QWebEngineView::setFocus()`
        instead of the `QWebEngineView` getting focus, the focus is given to another widget (in the program where I noticed the issue, it was a toolbar button). The difference with QTBUG-122153 is that in that case no widget ended up with focus, while here there is a widget with focus, but it's the wrong one.

      I attach a simple program which shows this behavior. The program automatically load an URL. If you enter a second URL in the line edit and press return, that URL is loaded in the view and the view should receive focus. Instead, the focus remains in the view. The program shows some debugging output to show when the focus widget changes and why. It looks like that the focus is first given to a `QQuickWidget`, which I imagine is inside the `QWebEngineView`, but then is given back to the line edit.

      //Just after pressing Return
      FOCUS CHANGED: OLD IS QLineEdit(0x55f0ed7b7860) NOW IS QQuickWidget(0x55f0ed552d20)
      Line Edit received focus. Reason: Qt::TabFocusReason
      FOCUS CHANGED: OLD IS QQuickWidget(0x55f0ed552d20) NOW IS QLineEdit(0x55f0ed7b7860)
      

       
      A work around for this problem is to call `QWebEngineView::setFocus` in response to its `loadFinished` signal (that is, uncommenting line 26).

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            anualiyas Anu Aliyas
            stefano.crocco Stefano Crocco
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes