Search code examples
pythonuser-interfacepyqt5qt-designer

Pyqt GUI Problem with High Resolution Screens


I've design my GUI with Qt Designer in low resolution screen (1366 * 768). But when I run my program in high resolution (high dpi) screens almost all fonts are messed up.

Login window in high dpi screen

Login window in high dpi screen

Login window in low resolution screen

Login window in low resolution screen

Create new user window in high dpi screen

Create new user window in high dpi screen

Create new user window in low resolution screen

Create new user window in low resolution screen

Product window in high dpi screen

Product window in high dpi screen

Product window in low resolution screen

Product window in low resolution screen

Any solution?

I've tried the below solution: https://leomoon.com/journal/python/high-dpi-scaling-in-pyqt5/

if __name__ == "__main__":
    app = QApplication(sys.argv)

    app.setAttribute(Qt.AA_EnableHighDpiScaling, True)
    app.setAttribute(Qt.AA_UseHighDpiPixmaps, True)

    login_window_started()
    sys.exit(app.exec_())

Solution

  • I have the solution, you need to place these commands:

    import PyQt5
    from PyQt5 import Qtcore
    PyQt5.QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True)
    

    as the first lines of your application (right under the imports).