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

Text of a Button that's in a Layout doesn't render at startup

    XMLWordPrintable

Details

    Description

      Run the following code. The text won't show up until it's resized with the sliders.

      import QtQuick 2.7
      import QtQuick.Layouts 1.3
      import QtQuick.Controls 2.3
      
      ApplicationWindow {
          id: window
          visible: true
          width: 400
          height: 680
      
          ColumnLayout {
              anchors.fill: parent
              anchors.margins: 8
              spacing: 20
      
              Slider {
                  id: controlWidthSlider
                  from: 1
                  // Setting value with a binding works
      //            value: button.implicitWidth
                  to: 200
              }
      
              Slider {
                  id: controlHeightSlider
                  from: 1
      //            value: button.implicitHeight
                  to: 100
              }
      
              // Using a plain item works
      //        Item {
      //            id: controlWidthSlider
      
      //            property real value
      //        }
      
      //        Item {
      //            id: controlHeightSlider
      
      //            property real value
      //        }
      
              Component.onCompleted: updateValues()
      
              function updateValues() {
                  controlWidthSlider.value = button.implicitWidth;
                  controlHeightSlider.value = button.implicitHeight;
              }
      
              Rectangle {
                  id: button
                  implicitWidth: Math.max(100, textItem.implicitWidth)
                  implicitHeight: Math.max(40, textItem.implicitHeight)
                  color: "grey"
      
                  property real leftPadding: 10
                  property real topPadding: 10
                  property alias text: textItem.text
      
                  Layout.preferredWidth: {
                      controlWidthSlider.value
                  }
                  Layout.preferredHeight: {
                      controlHeightSlider.value
                  }
      
                  Connections {
                      target: textItem
                      onWidthChanged: print(textItem.width)
                  }
      
                  Text {
                      id: textItem
                      text: "Button"
                      x: button.leftPadding
                      y: button.topPadding
                      width: button.width - button.leftPadding * 2
                      height: button.height - button.topPadding * 2
                      elide: Text.ElideRight
      
                      Rectangle {
                          anchors.fill: parent
                          color: "transparent"
                          border.color: "darkorange"
                      }
                  }
              }
          }
      }
      

      The issue was found here: https://codereview.qt-project.org/#/c/188942

      Attachments

        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
            mitch_curtis Mitch Curtis
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes