pythonresizepyqt5qapplication

PyQt5 Resize app for different displays


I am using PyQt5 and Python 3.6.4 to design a ui for a program. It was made on a 720p monitor however now using the same code on a 4k monitor, everything is tiny apart from the text. How would I go about resizing the whole app to look the same on all monitors: (720p, 1080p, 4k, etc.) The program is to be run on windows through an executable created through compiling the python code. Cheers


Solution

  • This is somewhat system dependent, so it would help if you mentioned your target platform(s).

    Because PyQt5 is just a wrapper around Qt5, I think High DPI Displays from the Qt manual applies. Citing the relevant bit (but you should read the whole thing):

    In order to get an application designed for low DPI values running on a high resolution monitors quickly, consider one of the scaling options (let the application run as DPI Unaware on Windows or set the environment variable QT_AUTO_SCREEN_SCALE_FACTOR to "1". These options may incur some scaling or painting artifacts, though.

    In the longer term, the application should be adapted to run unmodified:

    • Always use the qreal versions of the QPainter drawing API.
    • Size windows and dialogs in relation to the screen size.
    • Replace hard-coded sizes in layouts and drawing code by values calculated from font metrics or screen size.

    In a shell, you would do something like:

    $ export QT_AUTO_SCREEN_SCALE_FACTOR=1
    $ python my_application.py