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. How to size constrain a ColumnLayout?
Forum Updated to NodeBB v4.3 + New Features

How to size constrain a ColumnLayout?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
9 Posts 3 Posters 619 Views 1 Watching
  • 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.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by
    #1

    Hi all -

    My main window uses this code:

    import QtQml
    import QtQuick
    import QtQuick.Controls
    import QtQuick.Controls.Fusion
    import QtQuick.Controls.Basic
    import QtQuick.Controls.Material
    import QtQuick.Controls.Universal
    import QtQuick.Layouts
    
    ApplicationWindow {
        id: mainWindow
    
        readonly property real margin: width / 32.0
    
        visible: true
        width: 800
        height: 480
    
        menuBar: Maintabbar {
            id: navBar
            height: 56
            width: mainWindow.width
        }
    
        ColumnLayout {
            id: mainLayout
            height: mainWindow.height - navBar.height - mainWindow.margin
            width: mainWindow.width
            anchors {
                fill: parent
                leftMargin: margin
                rightMargin: margin
                bottomMargin: margin
            }
            Maincontent {
                id: mainContent
                // stuff here
            }
        }
    }
    

    I'm trying to get a margin on the sides and bottom of mainLayout. The left and right margins seem to be working, but my mainContent goes all the way to the bottom of the screen. Resizing the ColumnLayout doesn't seem to help. Any ideas what I'm missing here?

    Thanks...

    JoeCFDJ ? 2 Replies Last reply
    0
    • mzimmersM mzimmers

      Hi all -

      My main window uses this code:

      import QtQml
      import QtQuick
      import QtQuick.Controls
      import QtQuick.Controls.Fusion
      import QtQuick.Controls.Basic
      import QtQuick.Controls.Material
      import QtQuick.Controls.Universal
      import QtQuick.Layouts
      
      ApplicationWindow {
          id: mainWindow
      
          readonly property real margin: width / 32.0
      
          visible: true
          width: 800
          height: 480
      
          menuBar: Maintabbar {
              id: navBar
              height: 56
              width: mainWindow.width
          }
      
          ColumnLayout {
              id: mainLayout
              height: mainWindow.height - navBar.height - mainWindow.margin
              width: mainWindow.width
              anchors {
                  fill: parent
                  leftMargin: margin
                  rightMargin: margin
                  bottomMargin: margin
              }
              Maincontent {
                  id: mainContent
                  // stuff here
              }
          }
      }
      

      I'm trying to get a margin on the sides and bottom of mainLayout. The left and right margins seem to be working, but my mainContent goes all the way to the bottom of the screen. Resizing the ColumnLayout doesn't seem to help. Any ideas what I'm missing here?

      Thanks...

      JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by
      #2

      @mzimmers How do you set the size of Maincontent?

      mzimmersM 1 Reply Last reply
      0
      • JoeCFDJ JoeCFD

        @mzimmers How do you set the size of Maincontent?

        mzimmersM Offline
        mzimmersM Offline
        mzimmers
        wrote on last edited by
        #3

        @JoeCFD said in How to size constrain a ColumnLayout?:

        @mzimmers How do you set the size of Maincontent?

        Well, that's in flux, too. Ideally, I'd like to have it fill the available area. (There are a couple items above Maincontent that I left out of my snippet.) I've tried:

            Layout.fillHeight: true
            Layout.fillWidth: true
        

        but that doesn't work (in fact, it doesn't seem to have any effect, which is odd).

        If there's a better way to size it, I'm open.

        1 Reply Last reply
        0
        • mzimmersM mzimmers

          Hi all -

          My main window uses this code:

          import QtQml
          import QtQuick
          import QtQuick.Controls
          import QtQuick.Controls.Fusion
          import QtQuick.Controls.Basic
          import QtQuick.Controls.Material
          import QtQuick.Controls.Universal
          import QtQuick.Layouts
          
          ApplicationWindow {
              id: mainWindow
          
              readonly property real margin: width / 32.0
          
              visible: true
              width: 800
              height: 480
          
              menuBar: Maintabbar {
                  id: navBar
                  height: 56
                  width: mainWindow.width
              }
          
              ColumnLayout {
                  id: mainLayout
                  height: mainWindow.height - navBar.height - mainWindow.margin
                  width: mainWindow.width
                  anchors {
                      fill: parent
                      leftMargin: margin
                      rightMargin: margin
                      bottomMargin: margin
                  }
                  Maincontent {
                      id: mainContent
                      // stuff here
                  }
              }
          }
          

          I'm trying to get a margin on the sides and bottom of mainLayout. The left and right margins seem to be working, but my mainContent goes all the way to the bottom of the screen. Resizing the ColumnLayout doesn't seem to help. Any ideas what I'm missing here?

          Thanks...

          ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          @mzimmers said in How to size constrain a ColumnLayout?:

          but my mainContent goes all the way to the bottom of the screen. Resizing the ColumnLayout doesn't seem to help

          maybe stupid question : if the mainContent goes beyond the margins, wouldn't this simply be a clipping problem ?

          mzimmersM 1 Reply Last reply
          0
          • ? A Former User

            @mzimmers said in How to size constrain a ColumnLayout?:

            but my mainContent goes all the way to the bottom of the screen. Resizing the ColumnLayout doesn't seem to help

            maybe stupid question : if the mainContent goes beyond the margins, wouldn't this simply be a clipping problem ?

            mzimmersM Offline
            mzimmersM Offline
            mzimmers
            wrote on last edited by
            #5

            @ankou29666 mainContent is a StackLayout of various ColumnLayouts. I'm not sure where I'd apply the clipping.

            What I'm hoping for is to contain the size somewhere at the top level of my heirarchy so that everything underneath will observe it.

            JoeCFDJ 1 Reply Last reply
            0
            • mzimmersM mzimmers

              @ankou29666 mainContent is a StackLayout of various ColumnLayouts. I'm not sure where I'd apply the clipping.

              What I'm hoping for is to contain the size somewhere at the top level of my heirarchy so that everything underneath will observe it.

              JoeCFDJ Offline
              JoeCFDJ Offline
              JoeCFD
              wrote on last edited by
              #6

              @mzimmers
              this code works fine on Linux. Windows problem again?

              import QtQml
              import QtQuick
              import QtQuick.Controls
              import QtQuick.Controls.Fusion
              import QtQuick.Controls.Basic
              import QtQuick.Controls.Material
              import QtQuick.Controls.Universal
              import QtQuick.Layouts
              
              ApplicationWindow {
                  id: mainWindow
              
                  readonly property real margin: width / 32.0
              
                  visible: true
                  width: 800
                  height: 480
              
                  menuBar: Rectangle {
                      id: navBar
                      height: 56
                      width: mainWindow.width
                  }
              
                  ColumnLayout {
                      id: mainLayout
                      height: mainWindow.height - navBar.height - mainWindow.margin
                      width: mainWindow.width
                      anchors {
                          fill: parent
                          leftMargin: margin
                          rightMargin: margin
                          bottomMargin: margin
                      }
               
                      TextArea {
                          id: mainContent
                          Layout.fillHeight: true
                          Layout.fillWidth: true
                      }
                  }
              }
              
              mzimmersM 1 Reply Last reply
              1
              • JoeCFDJ JoeCFD

                @mzimmers
                this code works fine on Linux. Windows problem again?

                import QtQml
                import QtQuick
                import QtQuick.Controls
                import QtQuick.Controls.Fusion
                import QtQuick.Controls.Basic
                import QtQuick.Controls.Material
                import QtQuick.Controls.Universal
                import QtQuick.Layouts
                
                ApplicationWindow {
                    id: mainWindow
                
                    readonly property real margin: width / 32.0
                
                    visible: true
                    width: 800
                    height: 480
                
                    menuBar: Rectangle {
                        id: navBar
                        height: 56
                        width: mainWindow.width
                    }
                
                    ColumnLayout {
                        id: mainLayout
                        height: mainWindow.height - navBar.height - mainWindow.margin
                        width: mainWindow.width
                        anchors {
                            fill: parent
                            leftMargin: margin
                            rightMargin: margin
                            bottomMargin: margin
                        }
                 
                        TextArea {
                            id: mainContent
                            Layout.fillHeight: true
                            Layout.fillWidth: true
                        }
                    }
                }
                
                mzimmersM Offline
                mzimmersM Offline
                mzimmers
                wrote on last edited by
                #7

                @JoeCFD no, it works OK here, too. I even put a few things above your TextArea; still works.

                I replaced my Maincontent with a Rectangle, and it works fine, so there's something in my Maincontent that's ignoring the boundaries of the ColumnLayout. I'll have to dig a little to figure out what that is. I wish there were a way to force all children items to respect the boundaries of a parent, though.

                ? 1 Reply Last reply
                0
                • mzimmersM mzimmers

                  @JoeCFD no, it works OK here, too. I even put a few things above your TextArea; still works.

                  I replaced my Maincontent with a Rectangle, and it works fine, so there's something in my Maincontent that's ignoring the boundaries of the ColumnLayout. I'll have to dig a little to figure out what that is. I wish there were a way to force all children items to respect the boundaries of a parent, though.

                  ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by
                  #8

                  @mzimmers From what I read from this page https://doc.qt.io/qt-6/qml-qtquick-layouts-layout.html#fillHeight-attached-prop

                  layout.fillHeight/Width is false by default excepted for layout themselves (that is if I understand it right, layout nested in another layout). But as this is what you obviously want this is obviously not the problem. However check and see if there might be another "subtility" with layout inside another layout that might cause the problem.

                  mzimmersM 1 Reply Last reply
                  0
                  • ? A Former User

                    @mzimmers From what I read from this page https://doc.qt.io/qt-6/qml-qtquick-layouts-layout.html#fillHeight-attached-prop

                    layout.fillHeight/Width is false by default excepted for layout themselves (that is if I understand it right, layout nested in another layout). But as this is what you obviously want this is obviously not the problem. However check and see if there might be another "subtility" with layout inside another layout that might cause the problem.

                    mzimmersM Offline
                    mzimmersM Offline
                    mzimmers
                    wrote on last edited by
                    #9

                    @ankou29666 it turns out that the problem only occurs when I use a Module I created to create a custom list display. I'm going to close this topic and start a new one focused on that.

                    Thanks to all who looked...

                    1 Reply Last reply
                    0
                    • mzimmersM mzimmers has marked this topic as solved on

                    • Login

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