Search code examples
pythonqt5pyqt5dpi

PyQt 5 and 4k screen


I'm trying to migrate an existing PyQt5 app to high-dpi for window 10.

The documentation of Qt5 itself speak about high-dpi scaling here: http://doc.qt.io/qt-5/highdpi.html

QT_AUTO_SCREEN_SCALE_FACTOR to "1".

But i can't adapt this in python code :/

Any idea ?


Solution

  • Make sure you're on Qt 5.6+, skim the docs to be aware, then change your app init code to include one line before it and one line after it (written in Python) but it would be similar in C++:

    os.environ["QT_AUTO_SCREEN_SCALE_FACTOR"] = "1"
    qapp = QApplication(sys.argv)
    qapp.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)