I have a python application that simply displays given html, with the following code:
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QGridLayout
from PyQt5.QtWebEngineWidgets import QWebEngineView
class IFace(QWidget):
def __init__(self):
super().__init__()
self.setGeometry(300, 300, 1000, 500)
self.view = WebView(self)
self.setLayout(QGridLayout(self))
self.layout().addWidget(self.view, 0, 0)
self.layout().setContentsMargins(0, 0, 0, 0)
class WebView(QWebEngineView):
def __init__(self, parent):
super().__init__(parent)
self.setHtml("""<html><head></head><body><center>
<h1>Hi!</h1>
<h1>Hi!</h1>
<h1>Hi!</h1>
</body></html>""")
if __name__ == '__main__':
app = QApplication(sys.argv)
w = IFace()
w.show()
sys.exit(app.exec_())
The html is displayed correctly at first, but resizing the window vertically will cause the displayed webpage to 'stretch' downwards, distorting the text:
Note how the the text is taller, but not wider. The text also moves downwards as the window is shrunk vertically.
When I place another widget to the left of the QWebEngineView
, such as a QLabel
, the distortion affects the QLabel
as well. If I do not include the QWebEngineView
, the QLabel
is not distorted.
Why does this happen, and how can I fix it?
Thanks.
UPDATE:
It appears to have something to do with the instantiation of a QWebEngineView
that has the window as a parent, as the effect persists when the QWebEngineView
is only created not placed, and the effect does not remain when the QWebEngineView
is instantiated by QWebEngineView()
without the widget as a parent.
This problem occurred due to outdated drivers. I found the solution (also on stackoverflow) here, though it was to a slightly different problem (widgets being hidden beneath the title bar, not distortion of the QWebEngineView).
I updated my Intel(R) HD Graphics driver (forwards, unlike the listed answer in the link) and the issue went away.