diff --git a/aqt/__init__.py b/aqt/__init__.py index 3134df8d4..3a50634b9 100644 --- a/aqt/__init__.py +++ b/aqt/__init__.py @@ -223,8 +223,6 @@ 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(): @@ -261,8 +259,7 @@ def _run(argv=None, exec=True): ctypes.CDLL('libGL.so.1', ctypes.RTLD_GLOBAL) # opt in to full hidpi support - if not opts.lodpi: - QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling) + QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling) # create the app app = AnkiApp(argv) diff --git a/aqt/webview.py b/aqt/webview.py index 5c141e589..964774397 100644 --- a/aqt/webview.py +++ b/aqt/webview.py @@ -160,20 +160,33 @@ class AnkiWebView(QWebEngineView): from aqt import mw if isMac: return 1 - if isWin and mw.opts.lodpi: - return 1 screen = QApplication.desktop().screen() dpi = screen.logicalDpiX() factor = dpi / 96.0 if isLin: factor = max(1, factor) return factor - # compensate for qt's integer scaling - # on windows - qtIntScale = 72/screen.physicalDpiX() + # compensate for qt's integer scaling on windows + qtIntScale = self._getQtIntScale(screen) desiredScale = factor * qtIntScale newFactor = desiredScale / qtIntScale - return newFactor + return max(1, newFactor) + + def _getQtIntScale(self, screen): + # try to detect if Qt has scaled the screen + # - qt will round the scale factor to a whole number, so a dpi of 125% = 1x, + # and a dpi of 150% = 2x + # - a screen with a normal physical dpi of 72 will have a dpi of 32 + # if the scale factor has been rounded to 2x + # - different screens have different physical DPIs (eg 72, 93, 102) + # - until a better solution presents itself, assume a physical DPI at + # or above 70 is unscaled + if screen.physicalDpiX() > 70: + return 1 + elif screen.physicalDpiX() > 35: + return 2 + else: + return 3 def stdHtml(self, body, css=[], js=["jquery.js"], head=""): if isWin: