Details
-
Bug
-
Resolution: Duplicate
-
P2: Important
-
None
-
5.12.0
-
None
Description
With some fonts the width of the boundingRect as returned by QFontMetrics as got from the actual QLabel object seems to be out of sync with the width of what is actually rendered inside the QLabel.
Which breaks e.g. code which relies on the boundingRect to calculate some fixed size for a label widget.
Please find attached a sample program which should show the effect. Build & run it with:
qmake && make ./notometrics [fontfamily] [-f])
fontfamily defaults to "Noto Sans"
-f to set the label to the fixedsize as calculated via boundingRect
For fonts like "Liberation Sans" or "Droid Sans" the widths were identical.
For "Noto Sans" though things were out of sync by quite some pixels:
Which is quite surprising and seems like a bug, given the very QFontMetrics object was used that has been fetched from the very QLabel object, which by a quick look internally in the QLabel codebase at least in some path also seems to rely on that very QFontMetrics object.
Attachments
Issue Links
- relates to
-
QTBUG-7768 fontMetrics.boundingRect() and drawText(boundingRect) disagree about text width metrics
- Closed
-
QTBUG-85936 TextMetrics.width does not always give a correct width for the given text and is sometimes too short depending on the font used
- Closed