Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-79144

FontMetrics and Text element report different width for the same text



    • Task
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 5.10.1
    • None
    • Linux/Wayland, Linux/X11


      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.


        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.



              qt.team.quick.subscriptions Qt Quick and Widgets Team
              jpetrell Joona Petrell
              0 Vote for this issue
              3 Start watching this issue



                Gerrit Reviews

                  There are no open Gerrit changes