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

It should be possible to adapt the height of the StackLayout to its children's

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.7.1
    • Quick: Layouts
    • None

    Description

      Currently, the height of a StackLayout is always the height of its biggest child.

      The Layout.fillHeight and Layout.fillWidth proprties of its child items default to true. See https://bugreports.qt.io/browse/QTBUG-59711

      Now, if we want a StackLayout whose height automatically adapts to the height of its current child, it would be handy to have a simple property to allow that behaviour.

      Here is an alternative simplified implementation that behaves as explained above:

      /**
       * Custom implementation of a simplified StackLayout.
       * Its height adapts to the height of its current child.
       */
      import QtQuick 2.7
      import QtQuick.Controls 2.0
      import QtQuick.Layouts 1.3
      
      ColumnLayout {
          property int count: children.length
          property int currentIndex: 0
      
          onCurrentIndexChanged: {
              hideAllButCurrent();
          }
          Component.onCompleted: {
              hideAllButCurrent();
          }
      
          function hideAllButCurrent() {
              for (var i = 0; i < count; ++ i) {
                  var child = children[i];
                  if (i == currentIndex) {
                      child.visible = true;
                      child.enabled = true;
                  } else {
                      child.visible = false;
                      child.enabled = false;
                  }
              }
          }
      }
      

      Attachments

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

        Activity

          People

            smd Jan Arve
            mapmap Alexandre Quessy
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes