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

FontMetrics advanceWidth and boundingRect still disagree

    XMLWordPrintable

Details

    • Windows

    Description

      ... and advanceWidth doesn't match Text.implicitWidth.

      Even with the changes like https://codereview.qt-project.org/c/qt/qtbase/+/376365 for QTBUG-7768 / QTBUG-85936 the advanceWidth and bounding metrics still disagree.

      Also, despite the advice given in QTBUG-79144 and QTBUG-94023 the advanceWidth also isn't large enough to allow the Text element to render its text without eliding.

      Please see the attached example, where we expect the text "Elided" to be elided, but NOT either "One" or "Three".

       

      (Also a separate issue: I noticed that the advanceWidth value itself has changed between Qt 6.2.4 and Qt 6.5.3 with a particular font, cannot attach that example here, though.)

       

      Tested on Windows 11 with Qt 6.6.1 and with Qt 6.2.4, using msvc.

      Output follows:

       $ /mnt/c/Development/Qt/6.2.4/msvc2019_64/bin/qmlscene.exe test.qml
      qt.tools.qmlscene.deprecated: Warning: qmlscene is deprecated and will be removed in a future version of Qt. Please use qml instead.
      qml: debugElided text = Elided, implicitWidth = 33.328125, advanceWidth = 32.265625, boundingWidth = 31.296875, tightBoundingWidth = 30.203125
      qml: debugThree text = Three, implicitWidth = 31.328125, advanceWidth = 29.765625, boundingWidth = 29.296875, tightBoundingWidth = 29.0625
      qml: debugOne text = One, implicitWidth = 22.671875, advanceWidth = 22.09375, boundingWidth = 21.625, tightBoundingWidth = 21.078125
      
      $ /mnt/c/Development/Qt/6.6.1/msvc2019_64/bin/qmlscene.exe test.qml
      qt.tools.qmlscene.deprecated: Warning: qmlscene is deprecated and will be removed in a future version of Qt. Please use qml instead.
      qml: debugElided text = Elided, implicitWidth = 33.328125, advanceWidth = 32.265625, boundingWidth = 30.203125, tightBoundingWidth = 30.4375
      qml: debugThree text = Three, implicitWidth = 31.328125, advanceWidth = 29.765625, boundingWidth = 29.0625, tightBoundingWidth = 30
      qml: debugOne text = One, implicitWidth = 22.671875, advanceWidth = 22.09375, boundingWidth = 21.078125, tightBoundingWidth = 21.6875

       

      Example follows:

      import QtQuick
      
      Item {
          width: 400
          height: 400
      
          Row {
              anchors.centerIn: parent
              height: debugOne.height
              spacing: 4
      
              Text {
                  id: debugOne
                  width: Math.ceil(boundingWidth)
                  text: "One"
                  elide: Text.ElideRight
                  font.family: "Arial"
      
                  property real advanceWidth: fm.advanceWidth(text)
                  property real boundingWidth: fm.boundingRect(text).width
                  property real tightBoundingWidth: fm.tightBoundingRect(text).width
                  property FontMetrics fm: FontMetrics { font: debugOne.font }
      
                  Component.onCompleted: console.log("debugOne text = " + text
                          + ", implicitWidth = " + implicitWidth
                          + ", advanceWidth = " + advanceWidth
                          + ", boundingWidth = " + boundingWidth
                          + ", tightBoundingWidth = " + tightBoundingWidth)
              }
      
              Text {
                  id: debugThree
                  width: advanceWidth
                  text: "Three"
                  elide: Text.ElideRight
                  font.family: "Arial"
      
                  property real advanceWidth: fm.advanceWidth(text)
                  property real boundingWidth: fm.boundingRect(text).width
                  property real tightBoundingWidth: fm.tightBoundingRect(text).width
                  property FontMetrics fm: FontMetrics { font: debugThree.font } 
      
                  Component.onCompleted: console.log("debugThree text = " + text
                          + ", implicitWidth = " + implicitWidth
                          + ", advanceWidth = " + advanceWidth
                          + ", boundingWidth = " + boundingWidth
                          + ", tightBoundingWidth = " + tightBoundingWidth)
              }
      
              Text {
                  id: debugElided
                  width: Math.ceil(boundingWidth) - 8 // force elision
                  text: "Elided"
                  elide: Text.ElideRight
                  font.family: "Arial"
      
                  property real advanceWidth: fm.advanceWidth(text)
                  property real boundingWidth: fm.boundingRect(text).width
                  property real tightBoundingWidth: fm.tightBoundingRect(text).width
                  property FontMetrics fm: FontMetrics { font: debugElided.font }
      
                  Component.onCompleted: console.log("debugElided text = " + text
                          + ", implicitWidth = " + implicitWidth
                          + ", advanceWidth = " + advanceWidth
                          + ", boundingWidth = " + boundingWidth
                          + ", tightBoundingWidth = " + tightBoundingWidth)
              }
          }
      }

      Attachments

        Issue Links

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

          Activity

            People

              esabraha Eskil Abrahamsen Blomfeldt
              chrisadams Christopher Adams
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes