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

QML Text's implicitWidth is wrong when wrapMode is set for multiline text.

    XMLWordPrintable

Details

    • All
    • 013c346a8d (qt/qtbase/dev) 013c346a8d (qt/tqtc-qtbase/dev) 70e33a585c (qt/qtbase/6.4) 70e33a585c (qt/tqtc-qtbase/6.4) 07bde1cadf (qt/tqtc-qtbase/6.2)

    Description

      QML Text's implicit width is calculated incorrectly when wrapMode other than Text.NoWrap is used.

      See attached screenshot and sample code.

      This is very bad for scenarios where Text is used in layouts, because layouts use implicitWidth of content.

      import QtQuick 2.15
      import QtQuick.Layouts 1.15
      import QtQuick.Window 2.12
      
      Window {
          width: 640
          height: 480
          visible: true
          title: qsTr("Hello World")
      
          Rectangle {
              anchors.fill: layout
              color: 'transparent'
              border.color: '#999999'
              border.width: 1
              radius: 2
      
              Text {
                  anchors.bottom: parent.top
                  anchors.bottomMargin: 5
                  text: "Here everything is OK. Text's implicit width is correct, layout size is correct"
              }
          }
      
          ColumnLayout {
              id: layout
              x: 40
              y: 40
              spacing: 10
      
              Text {
                  text: 'Single line text'
      
                  Rectangle {
                      anchors.fill: parent
                      color: Qt.rgba(0,0,1,0.1)
                  }
              }
      
              Text {
                  text: 'Another single line text'
      
                  Rectangle {
                      anchors.fill: parent
                      color: Qt.rgba(0,0,1,0.1)
                  }
              }
      
              Text {
                  text: 'Multi line\ntext'
      
                  Rectangle {
                      anchors.fill: parent
                      color: Qt.rgba(0,0,1,0.1)
                  }
              }
          }
      
          Rectangle {
              anchors.fill: brokenLayout
              color: 'transparent'
              border.color: '#999999'
              border.width: 1
              radius: 2
      
              Text {
                  anchors.bottom: parent.top
                  anchors.bottomMargin: 5
                  text: "Now we add wrapMode to Text and implicit width is a sum of all lines widths"
              }
          }
      
          ColumnLayout {
              id: brokenLayout
              x: 40
              y: 40 + layout.height + 40
              spacing: 10
      
              Text {
                  text: 'Multi line\ntext'
                  wrapMode: Text.WrapAtWordBoundaryOrAnywhere
      
                  Rectangle {
                      anchors.fill: parent
                      color: Qt.rgba(1,0,0,0.1)
                  }
              }
      
              Text {
                  text: 'Another\nmulti\nline\ntext'
                  wrapMode: Text.WordWrap
      
                  Rectangle {
                      anchors.fill: parent
                      color: Qt.rgba(1,0,0,0.1)
                  }
              }
          }
      }
      

      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
              sergei.nevdakh Sergei Nevdakh
              Votes:
              8 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: