Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. StackLayout within ColumnLayout doesn't work
Forum Update on Monday, May 27th 2025

StackLayout within ColumnLayout doesn't work

Scheduled Pinned Locked Moved Solved QML and Qt Quick
12 Posts 3 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mzimmers
    wrote on 9 Mar 2023, 00:27 last edited by
    #1

    ...at least, not for me, the way I'm trying to use it.

    import QtQuick
    import QtQuick.Controls
    import QtQuick.Layouts
    
    ApplicationWindow {
    
        visible: true
        width: 800
        height: 480
    
        ColumnLayout {
            TabBar {
                spacing: 30
                ListModel {
                    id: prefsModel
                    ListElement { name: "tab 1" }
                    ListElement { name: "tab 2" }
                    ListElement { name: "tab 3" }
                }
    
                Repeater {
                    model: prefsModel
                    TabButton {
                        width: 60
                        text: qsTr(model.name)
                    }
                }
            }
    
            StackLayout {
                Rectangle {
                    implicitWidth: 40
                    implicitHeight: 40
                    color: 'red'
                }
            }
        }
    }
    

    Coded this way, my Rectangle becomes as wide as the TabBar. Removing the StackLayout, it functions properly (but in my real app, I need the StackLayout).

    What might I be doing wrong?

    Thanks...

    J 1 Reply Last reply 9 Mar 2023, 02:28
    0
    • J Offline
      J Offline
      jeremy_k
      wrote on 9 Mar 2023, 15:52 last edited by
      #10

      I think the key is this:
      https://doc.qt.io/qt-6/qml-qtquick-layouts-stacklayout.html

      In contrast to most other layouts, child Items' Layout.fillWidth and Layout.fillHeight properties default to true. As a consequence, child items are by default filled to match the size of the StackLayout as long as their Layout.maximumWidth or Layout.maximumHeight does not prevent it.

      Asking a question about code? http://eel.is/iso-c++/testcase/

      M 1 Reply Last reply 9 Mar 2023, 16:08
      2
      • M mzimmers
        9 Mar 2023, 00:27

        ...at least, not for me, the way I'm trying to use it.

        import QtQuick
        import QtQuick.Controls
        import QtQuick.Layouts
        
        ApplicationWindow {
        
            visible: true
            width: 800
            height: 480
        
            ColumnLayout {
                TabBar {
                    spacing: 30
                    ListModel {
                        id: prefsModel
                        ListElement { name: "tab 1" }
                        ListElement { name: "tab 2" }
                        ListElement { name: "tab 3" }
                    }
        
                    Repeater {
                        model: prefsModel
                        TabButton {
                            width: 60
                            text: qsTr(model.name)
                        }
                    }
                }
        
                StackLayout {
                    Rectangle {
                        implicitWidth: 40
                        implicitHeight: 40
                        color: 'red'
                    }
                }
            }
        }
        

        Coded this way, my Rectangle becomes as wide as the TabBar. Removing the StackLayout, it functions properly (but in my real app, I need the StackLayout).

        What might I be doing wrong?

        Thanks...

        J Offline
        J Offline
        jeremy_k
        wrote on 9 Mar 2023, 02:28 last edited by jeremy_k 3 Sept 2023, 02:28
        #2

        @mzimmers said in StackLayout within ColumnLayout doesn't work:

        [...]
                StackLayout {
                    Rectangle {
                        implicitWidth: 40
                        implicitHeight: 40
                        color: 'red'
                    }
                }
            }
        }
        

        Why is this using implicitWidth and implicitHeight instead of width and height?

        Asking a question about code? http://eel.is/iso-c++/testcase/

        M 1 Reply Last reply 9 Mar 2023, 02:30
        0
        • J jeremy_k
          9 Mar 2023, 02:28

          @mzimmers said in StackLayout within ColumnLayout doesn't work:

          [...]
                  StackLayout {
                      Rectangle {
                          implicitWidth: 40
                          implicitHeight: 40
                          color: 'red'
                      }
                  }
              }
          }
          

          Why is this using implicitWidth and implicitHeight instead of width and height?

          M Offline
          M Offline
          mzimmers
          wrote on 9 Mar 2023, 02:30 last edited by
          #3

          @jeremy_k said in StackLayout within ColumnLayout doesn't work:

          Why is this using implicitWidth and implicitHeight instead of width and height?

          That's an artifact from my "real" code. Works the same way with just width and height.

          J 1 Reply Last reply 9 Mar 2023, 02:39
          0
          • M mzimmers
            9 Mar 2023, 02:30

            @jeremy_k said in StackLayout within ColumnLayout doesn't work:

            Why is this using implicitWidth and implicitHeight instead of width and height?

            That's an artifact from my "real" code. Works the same way with just width and height.

            J Offline
            J Offline
            jeremy_k
            wrote on 9 Mar 2023, 02:39 last edited by
            #4

            @mzimmers said in StackLayout within ColumnLayout doesn't work:

            @jeremy_k said in StackLayout within ColumnLayout doesn't work:

            Why is this using implicitWidth and implicitHeight instead of width and height?

            That's an artifact from my "real" code. Works the same way with just width and height.

            Thanks for the clarification. I was looking for and failing to find use as a component, which didn't make the cut.

            I'm presuming from the lack of import versioning that this is happening with Qt 6. Is it platform and minor/patch version agnostic?

            Asking a question about code? http://eel.is/iso-c++/testcase/

            M 1 Reply Last reply 9 Mar 2023, 02:41
            0
            • J jeremy_k
              9 Mar 2023, 02:39

              @mzimmers said in StackLayout within ColumnLayout doesn't work:

              @jeremy_k said in StackLayout within ColumnLayout doesn't work:

              Why is this using implicitWidth and implicitHeight instead of width and height?

              That's an artifact from my "real" code. Works the same way with just width and height.

              Thanks for the clarification. I was looking for and failing to find use as a component, which didn't make the cut.

              I'm presuming from the lack of import versioning that this is happening with Qt 6. Is it platform and minor/patch version agnostic?

              M Offline
              M Offline
              mzimmers
              wrote on 9 Mar 2023, 02:41 last edited by
              #5

              @jeremy_k said in StackLayout within ColumnLayout doesn't work:

              I'm presuming from the lack of import versioning that this is happening with Qt 6. Is it platform and minor/patch version agnostic?

              Yes, I'm using 6.4.2. Occurs on Windows. I could test it on Android if desired. I haven't applied any patches.

              JoeCFDJ 1 Reply Last reply 9 Mar 2023, 04:57
              0
              • M mzimmers
                9 Mar 2023, 02:41

                @jeremy_k said in StackLayout within ColumnLayout doesn't work:

                I'm presuming from the lack of import versioning that this is happening with Qt 6. Is it platform and minor/patch version agnostic?

                Yes, I'm using 6.4.2. Occurs on Windows. I could test it on Android if desired. I haven't applied any patches.

                JoeCFDJ Offline
                JoeCFDJ Offline
                JoeCFD
                wrote on 9 Mar 2023, 04:57 last edited by
                #6
                This post is deleted!
                M 1 Reply Last reply 9 Mar 2023, 14:28
                0
                • JoeCFDJ JoeCFD
                  9 Mar 2023, 04:57

                  This post is deleted!

                  M Offline
                  M Offline
                  mzimmers
                  wrote on 9 Mar 2023, 14:28 last edited by
                  #7

                  @JoeCFD this is example is heavily reduced from my real app. Setting minimum and maximum values isn't feasible for that.

                  What I really want to know is why this is behaving the way it is. I can't find anything in the docs about nesting layouts causing problems, so it seems as though it should be OK.

                  JoeCFDJ 1 Reply Last reply 9 Mar 2023, 14:43
                  0
                  • M mzimmers
                    9 Mar 2023, 14:28

                    @JoeCFD this is example is heavily reduced from my real app. Setting minimum and maximum values isn't feasible for that.

                    What I really want to know is why this is behaving the way it is. I can't find anything in the docs about nesting layouts causing problems, so it seems as though it should be OK.

                    JoeCFDJ Offline
                    JoeCFDJ Offline
                    JoeCFD
                    wrote on 9 Mar 2023, 14:43 last edited by
                    #8
                    This post is deleted!
                    M 1 Reply Last reply 9 Mar 2023, 15:47
                    0
                    • JoeCFDJ JoeCFD
                      9 Mar 2023, 14:43

                      This post is deleted!

                      M Offline
                      M Offline
                      mzimmers
                      wrote on 9 Mar 2023, 15:47 last edited by
                      #9

                      @JoeCFD according to the docs, there is no minimum/maximum height/width for a Rectangle (or for an Item).

                      JoeCFDJ 1 Reply Last reply 9 Mar 2023, 15:59
                      0
                      • J Offline
                        J Offline
                        jeremy_k
                        wrote on 9 Mar 2023, 15:52 last edited by
                        #10

                        I think the key is this:
                        https://doc.qt.io/qt-6/qml-qtquick-layouts-stacklayout.html

                        In contrast to most other layouts, child Items' Layout.fillWidth and Layout.fillHeight properties default to true. As a consequence, child items are by default filled to match the size of the StackLayout as long as their Layout.maximumWidth or Layout.maximumHeight does not prevent it.

                        Asking a question about code? http://eel.is/iso-c++/testcase/

                        M 1 Reply Last reply 9 Mar 2023, 16:08
                        2
                        • M mzimmers
                          9 Mar 2023, 15:47

                          @JoeCFD according to the docs, there is no minimum/maximum height/width for a Rectangle (or for an Item).

                          JoeCFDJ Offline
                          JoeCFDJ Offline
                          JoeCFD
                          wrote on 9 Mar 2023, 15:59 last edited by JoeCFD 3 Sept 2023, 16:06
                          #11

                          @mzimmers Sorry. I got this from ApplicationWindow. That was wrong for Rectangle.

                          1 Reply Last reply
                          0
                          • M mzimmers has marked this topic as solved on 9 Mar 2023, 16:07
                          • J jeremy_k
                            9 Mar 2023, 15:52

                            I think the key is this:
                            https://doc.qt.io/qt-6/qml-qtquick-layouts-stacklayout.html

                            In contrast to most other layouts, child Items' Layout.fillWidth and Layout.fillHeight properties default to true. As a consequence, child items are by default filled to match the size of the StackLayout as long as their Layout.maximumWidth or Layout.maximumHeight does not prevent it.

                            M Offline
                            M Offline
                            mzimmers
                            wrote on 9 Mar 2023, 16:08 last edited by
                            #12

                            @jeremy_k that indeed was it. Good catch.

                            Thanks to all who looked.

                            1 Reply Last reply
                            0

                            1/12

                            9 Mar 2023, 00:27

                            • Login

                            • Login or register to search.
                            1 out of 12
                            • First post
                              1/12
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved