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

Pane's documentation doesn't fully explain contentWidth/Height behaviour

    XMLWordPrintable

Details

    • f5f36b0db64e77822ef3053245c993ed14949192 (qt/qtquickcontrols2/5.12)

    Description

      https://doc.qt.io/qt-5/qml-qtquick-controls2-pane.html#content-sizing says:

      If only a single item is used within a Pane, it will resize to fit the implicit size of its contained item. This makes it particularly suitable for use together with layouts.

      It then shows an example of this:

      Pane {
          ColumnLayout {
              anchors.fill: parent
              CheckBox { text: qsTr("E-mail") }
              CheckBox { text: qsTr("Calendar") }
              CheckBox { text: qsTr("Contacts") }
          }
      }
      

      What it doesn't mention is that if the contentItem has no implicitWidth/Height, it will use the implicitWidth/Height of the first child item of contentItem. This previously happened here in QML, and happens here in C++ in 5.12.

      This surprised me, as I understand that the following code would result in the contentWidth being equal to the implicitWidth of the text:

      import QtQuick 2.10
      import QtQuick.Window 2.10
      import QtQuick.Controls 2.3
      
      Window {
          id: root
          width: 400
          height: 440
          visible: true
          title: pane.contentWidth
      
          Pane {
              id: pane
      
              contentItem: Label {
                  text: "Info!"
                  anchors.centerIn: parent
              }
          }
      }
      

      But I wouldn't expect it to use the Label's implicitWidth here:

      import QtQuick 2.10
      import QtQuick.Window 2.10
      import QtQuick.Controls 2.3
      
      Window {
          id: root
          width: 400
          height: 440
          visible: true
          title: pane.contentWidth
      
          Pane {
              id: pane
      
              contentItem: Item {
                  Label {
                      text: "Info!"
                      anchors.centerIn: parent
                  }
              }
          }
      }
      

      Attachments

        Issue Links

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

          Activity

            People

              mitch_curtis Mitch Curtis
              mitch_curtis Mitch Curtis
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes