Details
-
Bug
-
Resolution: Invalid
-
P2: Important
-
None
-
6.5
-
None
-
Windows, Python 3.10 installed both PySide2 (Qt5) and PySide6 (Qt6) using pip
4K Monitor, OS scaling set to 100% or 150% will give the same result
Description
Reported font height (ascent+descent) as well as character width (QFont::boundingRect) measurements for the same font are different between Qt5 and Qt6.
Our C++ application relies on on height measurements to define the display layour and because Qt5 and Qt6 are reporting slightly different values, our application UI is not identical between Qt5 and Qt6.
Difference is not systhematic and apear more often with small fonts. We noticed that both Qt::AA_EnableHighDpiScaling and QGuiApplication::setHighDpiScaleFactorRoundingPolicy affected the reported dimentions but the impact was different between Qt5 and Qt6. Our application disables HighDpiScaling.
The following PySide code snipset demonstrate the problem. It can be run under python 3.10. Using PySide2 for Qt5 and or PySide6 for Qt6:
# This example prints the Ascent and Descent dimesiosn for the Segoe UI and Arial size 11 fonts # Returned values will differ between Qt 5 and Qt6 # Edit the next 2 lines (changing for PySide6 to run with Qt6) from PySide2.QtCore import Qt, QCoreApplication from PySide2.QtGui import QGuiApplication, QFont, QFontMetrics QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling, False ) qga = QGuiApplication() def test( fontName ): font = QFont( fontName, -1, QFont.Normal ) font.setPixelSize( 11 ) print( "QFont.toString: ", font.toString() ) fm = QFontMetrics( font ) print( "A : ", fm.ascent(), " D : ", fm.descent(), "Rec :", fm.boundingRect( "This is a very long text string" ) ) test( "Segoe UI" ) # Qt5 A=11 D=2 QT6 A=12 D=3 test( "Arial" ) # Qt5 A=11 D=3 Qt6 A=10 D=2
UPDATE: I have attached a C++ implementation of this reproducer .