Set webview bg to system default window color instead of Qt.transparent

Qt.transparent prevents subpixel anti-aliasing from working, resulting
in slightly blurry fonts on non-retina displays.
(The window background color is not determined correctly on macOS, so
we hardcode it.)

Credits for discovering this issue go to the unknown author of
https://ankiweb.net/shared/info/94394764
This commit is contained in:
Glutanimate 2019-02-25 11:44:27 +01:00
parent 3b4ed41c5b
commit ac53a0852e

View file

@ -18,7 +18,6 @@ class AnkiWebPage(QWebEnginePage):
QWebEnginePage.__init__(self)
self._onBridgeCmd = onBridgeCmd
self._setupBridge()
self.setBackgroundColor(Qt.transparent)
def _setupBridge(self):
class Bridge(QObject):
@ -93,6 +92,7 @@ class AnkiWebView(QWebEngineView):
QWebEngineView.__init__(self, parent=parent)
self.title = "default"
self._page = AnkiWebPage(self._onBridgeCmd)
self._page.setBackgroundColor(self._getWindowColor()) # reduce flicker
self._domDone = True
self._pendingActions = []
@ -216,6 +216,12 @@ class AnkiWebView(QWebEngineView):
else:
return 3
def _getWindowColor(self):
if isMac:
# standard palette does not return correct window color on macOS
return QColor("#ececec")
return self.style().standardPalette().color(QPalette.Window)
def stdHtml(self, body, css=[], js=["jquery.js"], head=""):
if isWin:
widgetspec = "button { font-size: 12px; font-family:'Segoe UI'; }"
@ -263,7 +269,7 @@ div[contenteditable="true"]:focus {
<title>{}</title>
<style>
body {{ zoom: {}; {} }}
body {{ zoom: {}; background: {}; {} }}
{}
</style>
@ -271,7 +277,8 @@ body {{ zoom: {}; {} }}
</head>
<body>{}</body>
</html>""".format(self.title, self.zoomFactor(), fontspec, widgetspec, head, body)
</html>""".format(self.title, self.zoomFactor(), self._getWindowColor().name(),
fontspec, widgetspec, head, body)
#print(html)
self.setHtml(html)