mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 23:12:21 -04:00
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:
parent
3b4ed41c5b
commit
ac53a0852e
1 changed files with 10 additions and 3 deletions
|
@ -18,7 +18,6 @@ class AnkiWebPage(QWebEnginePage):
|
||||||
QWebEnginePage.__init__(self)
|
QWebEnginePage.__init__(self)
|
||||||
self._onBridgeCmd = onBridgeCmd
|
self._onBridgeCmd = onBridgeCmd
|
||||||
self._setupBridge()
|
self._setupBridge()
|
||||||
self.setBackgroundColor(Qt.transparent)
|
|
||||||
|
|
||||||
def _setupBridge(self):
|
def _setupBridge(self):
|
||||||
class Bridge(QObject):
|
class Bridge(QObject):
|
||||||
|
@ -93,6 +92,7 @@ class AnkiWebView(QWebEngineView):
|
||||||
QWebEngineView.__init__(self, parent=parent)
|
QWebEngineView.__init__(self, parent=parent)
|
||||||
self.title = "default"
|
self.title = "default"
|
||||||
self._page = AnkiWebPage(self._onBridgeCmd)
|
self._page = AnkiWebPage(self._onBridgeCmd)
|
||||||
|
self._page.setBackgroundColor(self._getWindowColor()) # reduce flicker
|
||||||
|
|
||||||
self._domDone = True
|
self._domDone = True
|
||||||
self._pendingActions = []
|
self._pendingActions = []
|
||||||
|
@ -216,6 +216,12 @@ class AnkiWebView(QWebEngineView):
|
||||||
else:
|
else:
|
||||||
return 3
|
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=""):
|
def stdHtml(self, body, css=[], js=["jquery.js"], head=""):
|
||||||
if isWin:
|
if isWin:
|
||||||
widgetspec = "button { font-size: 12px; font-family:'Segoe UI'; }"
|
widgetspec = "button { font-size: 12px; font-family:'Segoe UI'; }"
|
||||||
|
@ -263,7 +269,7 @@ div[contenteditable="true"]:focus {
|
||||||
<title>{}</title>
|
<title>{}</title>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
body {{ zoom: {}; {} }}
|
body {{ zoom: {}; background: {}; {} }}
|
||||||
{}
|
{}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
@ -271,7 +277,8 @@ body {{ zoom: {}; {} }}
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>{}</body>
|
<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)
|
#print(html)
|
||||||
self.setHtml(html)
|
self.setHtml(html)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue