Skip to content

High DPI Scaling In PyQt5

Ultra HD screens are getting more popular these days. They typically run at 2160 x 1440 for 2k or 3840 x 2160 for 4k screens which is two and four times as many pixels as regular HD screens. Because the DPI is very high, text and graphics become too small. Windows and other OS use custom scaling to scale things up.

This means in order for your programs to scale properly you have to implement high DPI scaling in your program.

Two lies below must be added after import section.

import sys
from PyQt5 import QtWidgets, QtCore, QtGui #pyqt stuff

QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True) #enable highdpi scaling
QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps, True) #use highdpi icons

#rest of your code...