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. ColumnLayout: setting height of child
Qt 6.11 is out! See what's new in the release blog

ColumnLayout: setting height of child

Scheduled Pinned Locked Moved Solved QML and Qt Quick
7 Posts 3 Posters 1.5k 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 -

    I've got an app that looks something like this:

    ApplicationWindow {
        width: 800
        height: 480
    
        Rectangle {
            anchors.fill: parent
    
            ColumnLayout {
                width: parent.width
                Navbar { Layout.minimumHeight: 48 }
                Rectangle { height: 48 }
                Mainarea {
                    Layout.fillHeight: true // how to set height here?
                }
            }
        }
    }
    

    (The first rectangle is so I can give a background color to the entire window.)

    I want my Mainarea to take up all the vertical space not used by the first two items in the ColumnLayout. Is this value already derived for me somewhere, or do I need to calculate it manually?

    Thanks...

    1 Reply Last reply
    0
    • JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by
      #2

      set id to ApplicationWIndow
      id: mainWindow
      Mainarea {
      height: mainWindow.availableHeight
      }

      mzimmersM 1 Reply Last reply
      1
      • JoeCFDJ JoeCFD

        set id to ApplicationWIndow
        id: mainWindow
        Mainarea {
        height: mainWindow.availableHeight
        }

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

        @JoeCFD I've reduced this to a self-contained example:

        ApplicationWindow {
            id: mainWindow
            width: 800
            height: 480
        
        	ColumnLayout {
        		Item { Layout.minimumHeight: 48 }
        		Rectangle { height: 48 }
        		Rectangle {
        			height: mainWindow.availableHeight
        			Text {
        				text: height.toString()
        			}
        		}
        	}
        }
        

        The text denoting the available height is "16."

        1 Reply Last reply
        0
        • JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by
          #4

          your layout does not fill the mainWindow

          mzimmersM 1 Reply Last reply
          1
          • JoeCFDJ JoeCFD

            your layout does not fill the mainWindow

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

            @JoeCFD I've tried:

            ApplicationWindow {
                id: mainWindow
                visible: true
                width: 800
                height: 480
            
                ColumnLayout {
                    Layout.fillHeight: true
                    Layout.fillWidth: true
                    Item { Layout.minimumHeight: 48 }
                    Rectangle { height: 48 }
                    Rectangle {
                        id: rect
                        height: mainWindow.availableHeight
                        width: mainWindow.availableWidth
                        Text {
                            text: rect.height.toString() + " " + rect.width.toString()
                        }
                    }
                }
            }
            

            I get a "0 0" with this.

            I also tried an "anchors.fill: parent" and with this, I don't see any output at all. I must be using the wrong method to fill. Recommendation?

            Thanks...

            L 1 Reply Last reply
            0
            • mzimmersM mzimmers

              @JoeCFD I've tried:

              ApplicationWindow {
                  id: mainWindow
                  visible: true
                  width: 800
                  height: 480
              
                  ColumnLayout {
                      Layout.fillHeight: true
                      Layout.fillWidth: true
                      Item { Layout.minimumHeight: 48 }
                      Rectangle { height: 48 }
                      Rectangle {
                          id: rect
                          height: mainWindow.availableHeight
                          width: mainWindow.availableWidth
                          Text {
                              text: rect.height.toString() + " " + rect.width.toString()
                          }
                      }
                  }
              }
              

              I get a "0 0" with this.

              I also tried an "anchors.fill: parent" and with this, I don't see any output at all. I must be using the wrong method to fill. Recommendation?

              Thanks...

              L Offline
              L Offline
              lemons
              wrote on last edited by
              #6

              @mzimmers

              ApplicationWindow {
                 id: mainWindow
                 visible: true
                 width: 800
                 height: 480
              
                 ColumnLayout {
                     // Layout.fillWidth | Layout.fillHeight is only used if the parent is a layout as well
                     // else use anchors
                     anchors.fill: parent
                     spacing: 0
                     Rectangle {
                         color: "green"
                         Layout.minimumHeight: 48
                         Layout.preferredWidth: parent.width / 2
                     }
                     Rectangle {
                         color: "red"
                         width: 48
                         height: 48
                         Layout.alignment: Qt.AlignHCenter
                     }
                     Rectangle {
                         id: rect
                         Layout.fillHeight: true
                         Layout.fillWidth: true
                         color: "blue"
                         Text {
                             text: rect.height.toString() + " " + rect.width.toString()
                         }
                     }
                 }
              }
              
              mzimmersM 1 Reply Last reply
              1
              • L lemons

                @mzimmers

                ApplicationWindow {
                   id: mainWindow
                   visible: true
                   width: 800
                   height: 480
                
                   ColumnLayout {
                       // Layout.fillWidth | Layout.fillHeight is only used if the parent is a layout as well
                       // else use anchors
                       anchors.fill: parent
                       spacing: 0
                       Rectangle {
                           color: "green"
                           Layout.minimumHeight: 48
                           Layout.preferredWidth: parent.width / 2
                       }
                       Rectangle {
                           color: "red"
                           width: 48
                           height: 48
                           Layout.alignment: Qt.AlignHCenter
                       }
                       Rectangle {
                           id: rect
                           Layout.fillHeight: true
                           Layout.fillWidth: true
                           color: "blue"
                           Text {
                               text: rect.height.toString() + " " + rect.width.toString()
                           }
                       }
                   }
                }
                
                mzimmersM Offline
                mzimmersM Offline
                mzimmers
                wrote on last edited by
                #7

                @lemons thank you -- that seems to have solved it. I'm still learning when and where to use the various positioners. It always seems so clear after someone shows me how to do it right...

                1 Reply Last reply
                0

                • Login

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