0

我有一个 python 应用程序,它只显示给定的 html,代码如下:

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_())

html 最初显示正确,但垂直调整窗口大小会导致显示的网页向下“拉伸”,从而扭曲文本:

调整大小之前: 未拉伸的 WebEngineView

调整大小后: 拉伸的 WebEngineView

请注意文本如何更高,但不是更宽。当窗口垂直缩小时,文本也会向下移动。

当我在 左侧放置另一个小部件时QWebEngineView,例如 a QLabel,失真QLabel也会影响 。如果我不包括QWebEngineViewQLabel则不会失真。

为什么会发生这种情况,我该如何解决?

谢谢。

更新:

它似乎与QWebEngineView将窗口作为父级的 a 的实例化有关,因为当仅创建未放置时效果仍然存在,并且在没有小部件作为父级的情况下实例化QWebEngineView时效果不会保留。QWebEngineViewQWebEngineView()

4

1 回答 1

0

由于驱动程序过时而出现此问题。我在这里找到了解决方案(也在stackoverflow上),尽管它是一个稍微不同的问题(小部件隐藏在标题栏下方,而不是QWebEngineView的失真)。

我更新了我的 Intel(R) HD Graphics 驱动程序(转发,与链接中列出的答案不同)并且问题消失了。

于 2018-08-25T22:10:30.770 回答