PyQt5 QWebEngineView causes blurry/fuzzy scaling i

2019-08-18 11:05发布

问题:

When a QWebEngineView is added to the window, it causes strange scaling issues across the entire window. This is seen with the latest version of PyQt5 from pip (PyQt5=5.9, Qt5=5.9.1), Python 3.6, and Windows 10. For example:

from PyQt5 import QtGui, QtCore, QtWidgets
from PyQt5 import QtWebEngineWidgets
#
class WebViewer(QtWebEngineWidgets.QWebEngineView):
    def __init__(self, parent=None):
        super().__init__(parent)
        page = QtWebEngineWidgets.QWebEnginePage(self)
        self.setPage(page)
        self.setUrl(QtCore.QUrl('http://apple.com'))
    #
#
if __name__ == '__main__':
    appQT = QtWidgets.QApplication([])
    #
    main_widget = QtWidgets.QWidget(None)
    window_layout = QtWidgets.QVBoxLayout(main_widget)
    #
    window_layout.addWidget(QtWidgets.QTextEdit("1. abc<br/>2. def<br/>3. ghi", main_widget))
    ####window_layout.addWidget(WebViewer(main_widget))
    #
    main_widget.show()
    appQT.exec_()
#

Results in:

If I uncomment the window_layout.addWidget(WebViewer(main_widget)) line, I get:

The mouse position also does not correspond with what Qt thinks it's clicking on. Is this a bug in Qt5, or is there some dpi/scaling setting I should change? This is also seen with PyQt5.7.1 and PyQt5.8. This doesn't occur with a QWebView in older versions of PyQt5.