PyQt font size changes with windows display configurations

Viewed 4904

I am working on a PyQt4 GUI. During testing I recognized that the font size of all QLabels changes on diffrent computers. Apprently the windows display configurations can be changed from 100% to 125% or 150%, which then changed the fontsize of my widgets.

Is there an option where I can force the GUI to keep its fontsize independently from the display settings?

Thanks in advance for your help.


Edit:
I seached for the correct terminology, but best I get is this: If you open Control Panel\Appearance and Personalization\Display you can change the font- and other displayed elements-size. This configuration is independent from the screen resolution, but I dont know if it is independent from the actual dpi of the screen. Since AA_DisableHighDpiScaling does not work on PyQt4 I'll have to keep looking for another solution.

3 Answers

I know this post is old, but I thought I would add my two cents. If you want to iterate through all Qlabels and allow user to change font size, the code below works well for me (using PyQt5)

# change font
def font_change(self):
    font, ok = QtWidgets.QFontDialog.getFont()
    if ok:
        for name, obj in inspect.getmembers(self):
            if isinstance(obj, QtWidgets.QLabel):
                obj.setFont(font)

I too struggled with this problem on a application I was working on recently. I tired the other answers but was unable to get anything to work. What ended up being the solution for me was to "fix" a font size for each label and button in the stylesheet editor in QT Designer.

QT Designer Stylesheet Property

QT Designer Stylesheet Editor

You could also programmatically set this with the .setStyleSheet() method in the code as well. Both solutions worked perfectly in my PyQT5 app on Windows 10.

Related