This commit is contained in:
Florian Bruhin 2018-06-06 18:07:56 +02:00
parent 5147fc832c
commit 7e31897dcc
3 changed files with 18 additions and 2 deletions

View File

@ -30,7 +30,7 @@ from PyQt5.QtCore import (pyqtSignal, pyqtSlot, Qt, QEvent, QPoint, QPointF,
QUrl, QTimer)
from PyQt5.QtGui import QKeyEvent, QIcon
from PyQt5.QtNetwork import QAuthenticator
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWebEngineWidgets import QWebEnginePage, QWebEngineScript
from qutebrowser.config import configdata, config

View File

@ -58,7 +58,12 @@ class WebEngineView(QWebEngineView):
self._layout = miscwidgets.PseudoLayout(self)
def render_widget(self):
"""Get the RenderWidgetHostViewQt for this view."""
"""Get the RenderWidgetHostViewQt for this view.
Normally, this would always be the focusProxy().
However, it sometimes isn't, so we use this as a WORKAROUND for
https://bugreports.qt.io/browse/QTBUG-68727
"""
proxy = self.focusProxy()
if proxy is not None:
return proxy

View File

@ -268,6 +268,15 @@ class WrapperLayout(QLayout):
class PseudoLayout(QLayout):
"""A layout which isn't actually a real layout.
This is used to replace QWebEngineView's internal layout, as a WORKAROUND
for https://bugreports.qt.io/browse/QTBUG-68224 and other related issues.
This is partly inspired by https://codereview.qt-project.org/#/c/230894/
which does something similar as part of Qt.
"""
def addItem(self, item):
assert self.parent() is not None
item.widget().setParent(self.parent())
@ -285,11 +294,13 @@ class PseudoLayout(QLayout):
return self.parent().render_widget()
def setGeometry(self, rect):
"""Resize the render widget when the view is resized."""
widget = self.widget()
if widget is not None:
widget.setGeometry(rect)
def sizeHint(self):
"""Make sure the view has the sizeHint of the render widget."""
widget = self.widget()
if widget is not None:
return widget.sizeHint()