0

I've been programming an application with PySide2 and Python 3.8, and i was trying to enable HiDPi, and i found that adding this at the start of the script

QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True)
QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps, True)

was supposed to do the trick.

But it did not work for me. The window is shown with regular dpi (96ppp), while the whole system and apps are running on 125% (120ppp). Am I doing sth wrong?

Code:

import sys
from PySide2 import QtWidgets, QtGui, QtCore, QtMultimedia

"""
some functions
"""

if __name__ == "__main__":
    QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True)
    QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps, True)

    app = QtWidgets.QApplication(sys.argv)

    window = QtWidgets.QMainWindow()
    label = QtWidgets.QLabel(window)
    label.setText("hey")
    window.show()
    
    app.exec_()

Screenshot (On the screenshot is difficult to appreciate the difference, I'm sorry): enter image description here

System specs: Windows 10 Pro 64bit Python 3.7.8 PySide2 5.15.2

Martí Climent
  • 407
  • 4
  • 9

2 Answers2

2

For PySide2 as far as I can tell you need to run from the QCoreApplication, setting attributes before initialising the app.

        QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True)
        QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps, True)
        app = QtWidgets.QApplication(sys.argv)
Joseph
  • 578
  • 3
  • 15
0

I found the answer when testing the code on another computer. It seems like default Qt scaling alghoritm sets the scaling settings for 100-149% to 100% and 150% or + to 200% scaling.

I mean: If you have windows 10 scale set to 100% or 125%, it will be shown with 100% scaling

But instead, if you have windows 10 scale set to 150%, 175% or 200%, the window will be shown wit 200% scaling.

Martí Climent
  • 407
  • 4
  • 9