option to disable qt's hidpi scaling

https://anki.tenderapp.com/discussions/beta-testing/765-problem-with-the-ui-of-anki
This commit is contained in:
Damien Elmes 2017-10-02 16:19:34 +10:00
parent 384a01e53b
commit d530134218
2 changed files with 11 additions and 2 deletions

View file

@ -223,6 +223,8 @@ def parseArgs(argv):
parser.add_option("-b", "--base", help="path to base folder")
parser.add_option("-p", "--profile", help="profile name to load")
parser.add_option("-l", "--lang", help="interface language (en, de, etc)")
parser.add_option("--lodpi", action="store_true", dest="lodpi",
help="disable Qt's high DPI support")
return parser.parse_args(argv[1:])
def run():
@ -259,7 +261,8 @@ def _run(argv=None, exec=True):
ctypes.CDLL('libGL.so.1', ctypes.RTLD_GLOBAL)
# opt in to full hidpi support
QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
if not opts.lodpi:
QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
# create the app
app = AnkiApp(argv)

View file

@ -6,7 +6,7 @@ import sys
import math
from anki.hooks import runHook
from aqt.qt import *
from aqt.utils import openLink
from aqt.utils import openLink, showWarning
from anki.utils import isMac, isWin, isLin, devMode
# Page for debug messages
@ -73,6 +73,8 @@ class AnkiWebPage(QWebEnginePage):
# Main web view
##########################################################################
dpiWarned = False
class AnkiWebView(QWebEngineView):
def __init__(self, parent=None):
@ -157,6 +159,7 @@ class AnkiWebView(QWebEngineView):
oldFocus.setFocus()
def zoomFactor(self):
global dpiWarned
if isMac:
return 1
screen = QApplication.desktop().screen()
@ -167,6 +170,9 @@ class AnkiWebView(QWebEngineView):
return factor
# compensate for qt's integer scaling
# on windows
if isWin and screen.physicalDpiX() % 72 != 0 and not dpiWarned:
showWarning("Unexpected physical DPI - try starting Anki with --lodpi")
dpiWarned = True
qtIntScale = 72/screen.physicalDpiX()
desiredScale = factor * qtIntScale
newFactor = desiredScale / qtIntScale