Fonts too small with display scaling after Windows update
-
One recent update messed with font sizes in some parts of Qt. I expect that soon some of our clients will complain about this.
I am running Windows 11 21H2 (on an unsupported computer, hence I can't upgrade to 22H2 easily). The newly installed updates are KB5019961 and KB5020695. I am still using Qt 5.13.2, so this might be related to Qt 5.
My primary screen is a 4K monitor with 150% display scaling and I have a secondary monitor with 1080p and 100%.
The titles of main window and dialogs together with the menus have the correct font size. Also, I have seen a table widget to have the correct font size. Everywhere else the font size is too small (my guess is by a factor of 100/150). The problem persists when moving the widget to the secondary screen (Qt will resize the window title and menus properly, but other fonts also scale down by the same amount).
Does anyone have an idea how to fix this?
Is there a way to set the default font size to be used by everything in Qt?
Does anyone know a way to query which Windows updates have been installed to figure out if I have to change the font size at application startup?
Can anyone confirm this problem on their Windows 11 with Qt 5? Can anyone confirm that Qt 6 does not have this problem?
-
Alright, here is what I've gathered so far:
On Windows 100% scaling equals a DPI of 96. This is the definition (https://support.microsoft.com/en-us/topic/windows-scaling-issues-for-high-dpi-devices-508483cd-7c59-0d08-12b0-960b99aa347d).
Also, on Windows the device pixel ratio is always with respect to the primary screen (https://stackoverflow.com/a/74035135/6954968).
Combining this information means that the scaling I was looking for is primaryScreen.logicalDotsPerInchY/96. For my 4K display logicalDotsPerInchY yields 144 and 144/96 is 1.5 which corresponds to my Windows setting of 150% scaling.
And yes, using this to scale the default font size for the whole QApplication does the trick.
-
@SimonSchroeder said in Fonts too small with display scaling after Windows update:
Is there a way to set the default font size to be used by everything in Qt?
Figured that one out by myself. There is QApplication::setFont() which is applied correctly.
However, I cannot figure out the correct font scaling to apply. I have used qApp->primaryScreen()->devicePixelRatio(), but that returns '1' instead of '1.5' as is expected from the Windows setting of 150%.
-
Well, at the same time I rearranged my office and had to switch the monitor cables. So, most likely this is not related to the Windows update.
However, this is still highly confusing: When I change the primary screen in Windows the font size is correct, but other sizes aren't. It is also interesting to note that primaryScreen.devicePixelRatio yields the device pixel ratio of the first connected monitor (first one detected by Windows), but primaryScreen.logicalDotsPerInchY yields the resolution from the monitor that is configured as primary screen on Windows.
Another possible explanation is that primaryScreen.devicePixelRatio is always defined as '1' by Qt.
-
@SimonSchroeder This is messy stuff. One way to scale font size is to get the screen size first and then use its height or width or both to calculate a proper font size. Set it with QApplication::setFont() .
-
Alright, here is what I've gathered so far:
On Windows 100% scaling equals a DPI of 96. This is the definition (https://support.microsoft.com/en-us/topic/windows-scaling-issues-for-high-dpi-devices-508483cd-7c59-0d08-12b0-960b99aa347d).
Also, on Windows the device pixel ratio is always with respect to the primary screen (https://stackoverflow.com/a/74035135/6954968).
Combining this information means that the scaling I was looking for is primaryScreen.logicalDotsPerInchY/96. For my 4K display logicalDotsPerInchY yields 144 and 144/96 is 1.5 which corresponds to my Windows setting of 150% scaling.
And yes, using this to scale the default font size for the whole QApplication does the trick.
-
Well, my research checks out, but my solution was still wrong.
The solution worked on my computer, but it was not right on the next computer.
Turns out, it was a case of "did you try to turn it off an on again?": I didn't restart my computer after switching the primary monitor in Windows. This is the real solution!