Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.8.0
-
None
-
Linux, X11, 64 bit
-
a6c6665d79e6d4097c0a1155ff5f963b9a9eab19
Description
QWebEngineView::setFocus() does not work, it does not pass focus on to the underlying webkit widgets. This is most easily demonstrated by turning off FocusOnNavigationEnabled. With it off, if the html is loaded in a hidden QWebEngineView which is then shown with setVisbile(True), calling setFocus(True) does not actually pass focus to the web components. See minimal test case below.
This test case loads some HTML in a hidden QWebView() and then makes it visible and calls setFocus() on it. The QLineEdit that had focus initially no longer has focus, but neither does the webview have focus. Pressing the up/down arrow keys does not scroll the page. One has to click inside the web view to actually transfer focus to it. The autofocus attribute on the HTML textarea does not work either in this scenario.
If you remove the line that turns off FocusOnNavigationEnabled then everything works, presumably because that causes focusIfNeccessary() to call Focus() on load. So, the fix for this is probably to call webContents->Focus() in QWebEngineView::setFocus().
from PyQt5.Qt import * def show_view(): v.setHtml('''<html><body><textarea autofocus>some text</textarea>{}</body></html>'''.format( ''.join(f'<p>{i}</p>' for i in range(200)))) v.setVisible(True) v.setFocus() app = QApplication([]) d = QDialog() l = QVBoxLayout(d) b = QLineEdit() l.addWidget(b) v = QWebEngineView() s = v.page().settings() s.setAttribute(20, False) # FocusOnNavigationEnabled = 20 l.addWidget(v) d.resize(d.sizeHint()) v.setVisible(False) b.setFocus() QTimer.singleShot(100, show_view) d.exec_()