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

implicitHeight of wrapped text changes after it has became visible

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.10.1
    • None
    • Windows 10, MinGW x64

    Description

      I found a strange strange behavior of implicitHeight of the Text in StackLayout + ColumnLayout nesting, which looks like a bug for me.

      import QtQuick 2.10
      import QtQuick.Layouts 1.3
      import QtQuick.Window 2.3
      
      Window {
          visible: true
          width: 210
          height: 480
          title: "qtbug68356"
      
          StackLayout {
              anchors.fill: parent
              ColumnLayout {
                  Rectangle {
                      Layout.preferredHeight: 40
                      Layout.fillWidth: true
                      color: "red"
                  }
      
                  Text {
                      id: text
                      visible: false
                      Layout.leftMargin: 20
                      Layout.rightMargin: 20
                      Layout.fillWidth: true
                      wrapMode: Text.Wrap
                      text: "Subtitle. Lorem ipsum dolor sit amet, consectetur adipiscing elit."
                      onVisibleChanged: {
                          if (visible)
                              console.log("onVisibleChanged: ", implicitHeight)
                      }
                      onImplicitHeightChanged: console.log("onImplicitHeightChanged: ", implicitHeight)
                  }
      
                  MouseArea {
                      Layout.preferredHeight: 40
                      Layout.fillWidth: true
      
                      Rectangle {
                          anchors.fill: parent
                          color: "red"
                      }
      
                      onClicked: text.visible = !text.visible
                  }
              }
          }
      }
      

      If you press 2 times on rectangle, you'll get this:

      qml: onImplicitHeightChanged: 16
      qml: onImplicitHeightChanged: 16
      qml: onVisibleChanged: 16
      qml: onImplicitHeightChanged: 48
      qml: onVisibleChanged: 48
      

      As you can see implicitHeight of text changes after test has became visible. 

      So on first time you'll see this:

      And on second this:

      forceLayout() does not change anything.

      Attachments

        1. image-2018-05-18-15-04-48-799.png
          image-2018-05-18-15-04-48-799.png
          7 kB
        2. image-2018-05-18-15-05-50-156.png
          image-2018-05-18-15-05-50-156.png
          10 kB
        3. main.cpp
          0.3 kB
        4. main.qml
          2 kB
        5. qml.qrc
          0.1 kB

        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
              mabean Max Bespalov
              Votes:
              2 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes