From ac53a0852ecebeec48c5d6eb6132f2a7f2aeaa01 Mon Sep 17 00:00:00 2001 From: Glutanimate Date: Mon, 25 Feb 2019 11:44:27 +0100 Subject: [PATCH] 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 --- aqt/webview.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/aqt/webview.py b/aqt/webview.py index b75fa3557..093e74915 100644 --- a/aqt/webview.py +++ b/aqt/webview.py @@ -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 { {} @@ -271,7 +277,8 @@ body {{ zoom: {}; {} }} {} -""".format(self.title, self.zoomFactor(), fontspec, widgetspec, head, body) +""".format(self.title, self.zoomFactor(), self._getWindowColor().name(), + fontspec, widgetspec, head, body) #print(html) self.setHtml(html)