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

TextMetrics width is not same as Text.implicitWidth

    XMLWordPrintable

Details

    • Linux/X11, Windows

    Description

      When tried with the following code, it is expected that text width is same as TextMetrix width

       Text {
              id: txt
              text: qsTr("NOT FOR PATIENT USE")
              height: 14
              font.pixelSize: 11
              font.family: "Courier" // "Arial"
              color: "#2B2D2E"
              font.letterSpacing: 0
          }
          TextMetrics {
              id: textMetrics
              font: txt.font
              text: txt.text
          }
          Component.onCompleted: {
              console.log("textMetrics.width: ",textMetrics.width )
              console.log("txt.implicitWidth: ",txt.implicitWidth )
          }
      

      The output is gives:

      For "Arial" font:
      qml: textMetrics.width: 109
      qml: txt.implicitWidth: 125
      
      For "Courier" font:
      qml: textMetrics.width: 151
      qml: txt.implicitWidth: 152
      

      Attachments

        Issue Links

          Activity

            People

              qt.team.quick.subscriptions Qt Quick and Widgets Team
              shmittal Shveta Mittal (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: