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

FontMetrics and Text element report different width for the same text

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Priority: Not Evaluated
    • Resolution: Invalid
    • Affects Version/s: 5.10.1
    • Fix Version/s: None
    • Labels:
      None
    • Platform/s:
      Linux/Wayland, Linux/X11

      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

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

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes