QGraphicsScene font calculation incorrect in Windows 11
-
My app has the option of using QPainter or QGraphicsScene to calculate the size of strings of characters, and display them in a box.
In Windows 10 and previous versions, both work fine. In Windows 11, with QGraphicsScene the length of the characters as reported by Qt are understated, which results in the bounding box being too short:
If I switch to QPainter in Windows 11, I get correct results:
I am using Qt 5.15, and:
QFontMetrics const font_metrics(QFont, QPaintDevice *device); font_metrics.boundingRect(QString qstr)
I need to use QGraphicsScene for the faster performance.
Has anyone else seen this problem? Any suggestions?
I know there have been some changes in font metrics in Qt 6, but I'm not there yet, I need to get this to work in Qt 5 + Windows 11.
UPDATE
This is not a Windows 11 issue. It is caused by Display Scaling. At 100%, it looks OK. At 125%+, it protrudes. Further, the problem only occurs on the auxiliary (2nd) monitor, not on the main built-in display.