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. GridLayout: problems with columnSpan and rowSpan
Forum Update on Monday, May 27th 2025

GridLayout: problems with columnSpan and rowSpan

Scheduled Pinned Locked Moved Solved QML and Qt Quick
7 Posts 2 Posters 4.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
    MHermann
    wrote on 5 Dec 2017, 10:36 last edited by MHermann 12 May 2017, 10:38
    #1

    Hi all!

    Actually I am facing problems using a Grid Layout with columnSpan and rowSpan.
    The columnSpan is working. The green boxes have a width of 6 cells.
    But the rowSpan is not working. All boxes have the same height (GridLayout.height / 3). Why?

    Here is my example code:

    ...
    GridLayout {
        id: mainLayout1
        anchors.fill: parent
        rows: 13
        columns: 12
        rowSpacing: 4
        columnSpacing: 4
    
        Rectangle {
            color: "red"
            Layout.fillHeight: true
            Layout.fillWidth: true
            Layout.columnSpan: 12
            Layout.rowSpan: 1
        }
        
        Rectangle {
            color: "green"
            Layout.fillHeight: true
            Layout.fillWidth: true
            Layout.columnSpan: 6
            Layout.rowSpan: 10
        }
    
        Rectangle {
            color: "green"
            Layout.fillHeight: true
            Layout.fillWidth: true
            Layout.columnSpan: 6
            Layout.rowSpan: 10
        }
    
        Rectangle {
            color: "yellow"
            Layout.fillHeight: true
            Layout.fillWidth: true
            Layout.columnSpan: 12
            Layout.rowSpan: 2
        }
    }
    ...
    
    1 Reply Last reply
    0
    • M Offline
      M Offline
      mostefa
      wrote on 5 Dec 2017, 12:36 last edited by
      #2

      Hi @MHermann

      can you describe what you want to obtain with a picture ?

      M 1 Reply Last reply 6 Dec 2017, 06:44
      0
      • M mostefa
        5 Dec 2017, 12:36

        Hi @MHermann

        can you describe what you want to obtain with a picture ?

        M Offline
        M Offline
        MHermann
        wrote on 6 Dec 2017, 06:44 last edited by MHermann 12 Jun 2017, 06:45
        #3

        @mostefa :

        This is what I want to have:
        0_1512542614301_Unbenannt.jpg

        M 1 Reply Last reply 6 Dec 2017, 08:38
        0
        • M MHermann
          6 Dec 2017, 06:44

          @mostefa :

          This is what I want to have:
          0_1512542614301_Unbenannt.jpg

          M Offline
          M Offline
          mostefa
          wrote on 6 Dec 2017, 08:38 last edited by mostefa 12 Jun 2017, 08:40
          #4

          @MHermann

          Hi maybe you need to use a qml repeater

          Here is an example for two rows :

          GridLayout {
              id: mainLayout1
              anchors.fill: parent
              rows: 13
              columns: 12
              rowSpacing: 1
              columnSpacing: 4
          
              //red 
              Repeater {
                  model: 12
                  Rectangle {
                      color: "red"
                      Layout.fillHeight: true
                      Layout.fillWidth: true
                      Layout.columnSpan: 1
                      Layout.rowSpan: 1
                  }
              }
          
              Repeater{
                  model: 6
                  Rectangle{
                      color: "green"
                      Layout.fillHeight: true
                      Layout.fillWidth: true
                      Layout.columnSpan: 1
                      Layout.rowSpan: 1
                  }
              }
          
              Repeater{
                  model: 6
                  Rectangle{
                      color: "#00ee00"
                      Layout.fillHeight: true
                      Layout.fillWidth: true
                      Layout.columnSpan: 1
                      Layout.rowSpan: 1
                  }
              }
          }
          
          1 Reply Last reply
          0
          • M Offline
            M Offline
            mostefa
            wrote on 6 Dec 2017, 09:06 last edited by
            #5

            Or you can even do better:

            Something like this :

            ```
            

            GridLayout {
            id: mainLayout1
            anchors.fill: parent
            rows: 13
            columns: 12
            rowSpacing: 1
            columnSpacing: 4

                property var values: [ "red", "red", "red", "red", "red" , "red", "red", "red", "red", "red", "red" , "red",
                                       "green", "green","green", "green","green", "green","#00ee00", "#00ee00", "#00ee00", "#00ee00","#00ee00", "#00ee00" ]
            
            
            
                //red
                Repeater {
                    model: mainLayout1.values
                    Rectangle {
                        color: modelData
                        Layout.fillHeight: true
                        Layout.fillWidth: true
                        Layout.columnSpan: 1
                        Layout.rowSpan: 1
                    }
                }
            
            
            }
            
            M 1 Reply Last reply 6 Dec 2017, 09:15
            0
            • M mostefa
              6 Dec 2017, 09:06

              Or you can even do better:

              Something like this :

              ```
              

              GridLayout {
              id: mainLayout1
              anchors.fill: parent
              rows: 13
              columns: 12
              rowSpacing: 1
              columnSpacing: 4

                  property var values: [ "red", "red", "red", "red", "red" , "red", "red", "red", "red", "red", "red" , "red",
                                         "green", "green","green", "green","green", "green","#00ee00", "#00ee00", "#00ee00", "#00ee00","#00ee00", "#00ee00" ]
              
              
              
                  //red
                  Repeater {
                      model: mainLayout1.values
                      Rectangle {
                          color: modelData
                          Layout.fillHeight: true
                          Layout.fillWidth: true
                          Layout.columnSpan: 1
                          Layout.rowSpan: 1
                      }
                  }
              
              
              }
              
              M Offline
              M Offline
              MHermann
              wrote on 6 Dec 2017, 09:15 last edited by
              #6

              @mostefa : Thanks for your answers. But I think you missunderstood me. Maybe my picture was not clear.
              I want to have only four rectangles.

              • One red rectangle on the top which covers 1 row and 12 columns.
              • Two green rectangles where each covers 10 rows and 6 columns.
              • One yellow rectangle on the bottom which covers 2 rows and 12 columns.
              1 Reply Last reply
              0
              • M Offline
                M Offline
                MHermann
                wrote on 6 Dec 2017, 13:22 last edited by
                #7

                I solved the problem.

                ...
                GridLayout {
                    id: mainLayout1
                    anchors.fill: parent
                    rows: 13
                    columns: 12
                
                    property double colWidth: width/columns
                    property double rowHeight: height/rows
                
                    function prefWidth(item){
                        return ((colWidth * item.Layout.columnSpan) + (columnSpacing * (item.Layout.columnSpan-1)))
                    }
                    function prefHeight(item){
                        return ((rowHeight * item.Layout.rowSpan) + (rowSpacing * (item.Layout.rowSpan -1)))
                    }
                
                    Rectangle {
                        color: "red"
                        Layout.columnSpan: 12
                        Layout.rowSpan: 1
                        Layout.preferredWidth: mainLayout1.prefWidth(this)
                        Layout.preferredHeight: mainLayout1.prefHeight(this)
                    }
                    
                    Rectangle {
                        color: "green"
                        Layout.columnSpan: 6
                        Layout.rowSpan: 10
                        Layout.preferredWidth: mainLayout1.prefWidth(this)
                        Layout.preferredHeight: mainLayout1.prefHeight(this)
                    }
                
                    Rectangle {
                        color: "green"
                        Layout.columnSpan: 6
                        Layout.rowSpan: 10
                        Layout.preferredWidth: mainLayout1.prefWidth(this)
                        Layout.preferredHeight: mainLayout1.prefHeight(this)
                    }
                
                    Rectangle {
                        color: "yellow"
                        Layout.columnSpan: 12
                        Layout.rowSpan: 2
                        Layout.preferredWidth: mainLayout1.prefWidth(this)
                        Layout.preferredHeight: mainLayout1.prefHeight(this)
                    }
                }
                ...
                
                1 Reply Last reply
                1

                1/7

                5 Dec 2017, 10:36

                • Login

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