How to cater for Windows user text size in PyQt5?
-
Hi,
Sorry I can't answer that right away but you should give more information about your software stack and OS version so people can try to reproduce your issue.
-
Sure, no problem. Python 3.7, Qt / PyQt 5.14.2, Windows 10 version 1909. What other info would be helpful?
-
How you installed it can also be useful (conda VS pip VS ?)
-
I'm working in PyCharm 2019.12, which handles the installation of libraries from requirements.txt using (I think) pip.
I'm using PyInstaller to create executable files of the application to test on other machines, but get the same results when running directly in the PyCharm virtual environment too.
-
Can you check if you have the same issue with PySide2 ?
-
I can do that, but I've not used PySide2 at all so far so it might take me a little time. I'll get back to you.
-
OK, that didn't take anywhere near as long as I expected.
PySide2 appears to have the same problem- the text of items in the main window doesn't scale for the environment settings. Strangely, in PySide2 the status bar label at the bottom doesn't scale either, while in PyQt5, the status bar label did scale for text size.
So my question still remains- how am I meant to get my application to scale all the text to suit the user's accessibility settings, instead of just some of it? Are there changes or additions I can make to my code to make this work as expected on Windows, without affecting Mac users etc.?
The result I got from PySide2 was:
The 'correct' expected result would be that all the text would be large, the same size as the "One Two Three" on the menu bar, as this is what the Windows "make text bigger" settings ought to do- but Qt appears to only partially implement this?
The source code is exactly the same as before, but with the imports changed from PyQt5 to PySide2:
from PySide2 import QtCore from PySide2.QtWidgets import QApplication from PySide2.QtWidgets import QGridLayout, QLabel, QMainWindow, QPushButton, QFrame import sys class TestDialog(QMainWindow): def __init__(self, parent, windowTitle): super().__init__(parent) self.setWindowTitle(windowTitle) self.setWindowFlags(QtCore.Qt.Window | QtCore.Qt.WindowTitleHint | QtCore.Qt.WindowCloseButtonHint | QtCore.Qt.WindowStaysOnTopHint) self.name = windowTitle self.parent_window = parent menu = self.menuBar() menu.addAction("One") menu.addAction("Two") menu.addAction("Three") screen = QApplication.screens()[0] dpiScaling = screen.logicalDotsPerInch() self.frame = QFrame() self.grid = QGridLayout() self.frame.setLayout(self.grid) self.setCentralWidget(self.frame) self.scalingLabel = QLabel("DPI scaling: " + str(dpiScaling)) self.grid.addWidget(self.scalingLabel, 0, 0) self.uselessButton = QPushButton("Button in the main area") self.grid.addWidget(self.uselessButton, 1, 0) self.statusBar().addWidget(QLabel("Text on the status bar")) if __name__ == '__main__': app = QApplication(sys.argv) app.setStyleSheet("Fusion") windowTitle = "Scaling test" testDialog = TestDialog(None, windowTitle) testDialog.show() sys.exit(app.exec_())
-
Just to add, the above test was on PySide2 5.15.0. I've also just tested it with PyQt5 5.15.0 with the same results.
-
Then I would say you found a bug. You should check the bug report system to see if it's something known. If not please create a new report providing your examples and the results you obtained.
-
Thanks for the response. As you suggested, I have posted this as a potential bug, now visible at https://bugreports.qt.io/browse/QTBUG-85491
As far as I'm aware there's nothing that I could add to my code to compensate for this in the meantime? I can't see a Qt method or function that makes the Windows text size setting accessible so that it could be compensated for manually.