Details
-
Task
-
Resolution: Invalid
-
Not Evaluated
-
None
-
5.10.1
-
None
Description
FontMetrics is a convenient helper API for determining how much space particular text occupies. Those calculations can then be used to determine what font size, wrapping, truncation, eliding, etc. rules to select to optimize common shorter cases, but be ready to adapt to corner cases with unexceptionally long translations. Unfortunately FontMetrics seems to not be compatible with the dimension requirements of Text element that shares the same text and font.
Run following example.
import QtQuick 2.6 Text { id: label text: "Lorem lipsum" font.pixelSize: 100 Component.onCompleted: console.log(implicitWidth, metrics.boundingRect(text).width) FontMetrics { id: metrics font: label.font } }
Expected result: FontMetrics and implicit Text element report same space requirement for particular text and font.
Actual result: Text reserves 611.375 space and font metrics slightly less 596. Now FontMetrics will report text will fit, but Text element will end up truncated/elided or using too large font size that is appropriate.
Before FontMetrics dummy invisible Text elements were used to determine size requirements of a particular text, if FontMetrics cannot be trusted many need to revert back to using the dummy Text elements.
Attachments
Issue Links
- is replaced by
-
QTBUG-124588 FontMetrics advanceWidth and boundingRect still disagree
- Open
- relates to
-
QTBUG-7768 fontMetrics.boundingRect() and drawText(boundingRect) disagree about text width metrics
- Closed