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

implicitWidth of QQuickText is too big for multi-line text when wrapMode is Wrap

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.15.2
    • None
    • All

    Description

      The implicitWidth of a QQuickText is too big, when text is multi-line and wrapMode is Text.Wrap:

      Item {
        width: 400
        height: 400
        Rectangle {
          y: 100
          anchors.horizontalCenter: parent.horizontalCenter
          border.color: "orange"
          width: content1.implicitWidth
          height: content1.implicitHeight
          Text { id: content1
              text: "Hello, World!\n Hello again!\nNoWrap"
              wrapMode: Text.NoWrap
          }
        }
        Rectangle {
          y: 200
          anchors.horizontalCenter: parent.horizontalCenter
          border.color: "orange"
          width: content2.implicitWidth
          height: content2.implicitHeight
          Text { id: content2
              text: "Hello, World!\n Hello again!\nWrap"
              wrapMode: Text.Wrap
          }
        }
      }
      

      I would expect, that implicitWidth is the same for wrapMode=Text.NoWrap and wrapMode=Text.Wrap.

      This is the behaviour for single-line texts.

      This was noticed, when investigating, why multi-line tooltips are wider than necessary:

      import QtQuick 2.12
      import QtQuick.Controls 2.12
      
      ApplicationWindow {
        width: 640
        height: 480
        Button {
          anchors.centerIn: parent
          text: "test button"
      
          HoverHandler { id: hoverHandler2 }
          ToolTip.visible: hoverHandler2.hovered
          ToolTip.text: "Multi line\n2nd line\nBox is too wide"
        }
      }
      

       

      Attachments

        Issue Links

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

          Activity

            People

              qt.team.quick.subscriptions Qt Quick and Widgets Team
              florianrichter Florian Richter
              Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes