0

I'm using PyQt5 to create a login window. The window showed all the font at a normal size before I got a new laptop, now this laptop has a much higher resolution for the monitor. I'm struggling to get the size of the text back to normal.

Image of the enlarged text

The checkbox text should save Remember Server Information, but it's cropped because it's too big and so if the version in the bottom right. The other Text is also much larger than normal.

I've tried to use StyleSheets to change the font-size. I've also tried this:

if hasattr(QtCore.Qt, 'AA_EnableHighDpiScaling'):
        QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True)
if hasattr(QtCore.Qt, 'AA_UseHighDpiPixmaps'):
        QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps, True)

which doesn't seem to make a difference whether I have that there or not. If anyone has any words of advice to get the text to scale normally again it would be very appreciated.

EDIT:

This is also happening the in Qt Designer Tool.

enter image description here

Andew
  • 321
  • 1
  • 9
  • How are you specifying font sizes? Also, it doesn't seem like you're properly using layout managers. – musicamante Apr 07 '23 at 17:55
  • I'm building the UI using Qt Designer. The menus and text within the Qt Designer tool is also showing larger text. – Andew Apr 07 '23 at 18:13

1 Answers1

0

In case anyone else is having the issues I had, I believe I found my problem. I had a style sheet set for my MainWindow that called out specific widgets:

QLabel {
    color:black;
    font: regular "Segoe UI Semibold";
}

QLineEdit{
    color: black;
    background-color: white;
    border-radius: 1%;
}

QComboBox{
    color: black;
    background-color: white;
    border-radius: 1%;
}

When I apply this style sheet that's where my font sizes are getting all wonky with different DPI / Resolutions. I needed to specifically call out the font sizes as well or else they were getting scaled very small.

QLabel {
    color:black;
    font: regular "Segoe UI Semibold";
    font-size: 8pt;
}

QLineEdit{
    color: black;
    background-color: white;
    border-radius: 1%;
    font-size: 8pt;
}

QComboBox{
    color: black;
    background-color: white;
    border-radius: 1%;
    font-size: 8pt;
}

I also included these three lines, which seemed to actually make a difference when re-sizing the GUI across multiple different resolutions and different zoom levels.

os.environ["QT_ENABLE_HIGHDPI_SCALING"]   = "1"
os.environ["QT_AUTO_SCREEN_SCALE_FACTOR"] = "1"
os.environ["QT_SCALE_FACTOR"]             = "1

Also if you're using QtDesigner and not setting style sheets, upping the font size there also helps.

Andew
  • 321
  • 1
  • 9