0

Maybe I didn't understand some point about QtQuick.Layouts - GridLayout. I want to achieve the following:

4 columns layout. Red and green Rectangle takes 1 col and Blue take 2 cols.

This is a 4 columns layout. Red and green Rectangle takes 1 col and Blue take 2 cols. The code is:

Window {   
    visible: true
    width: 800
    height: 600
    GridLayout {
         id: grid
         anchors.fill: parent
         columns: 4
         Rectangle {
             Layout.fillWidth:true
             Layout.fillHeight:true
             Layout.columnSpan: 1
             color: "red"
         }
         Rectangle {
             Layout.fillWidth:true
             Layout.fillHeight:true
             Layout.columnSpan: 1
             color: "green"
         }
         Rectangle {
             Layout.fillWidth:true
             Layout.fillHeight:true
             Layout.columnSpan: 2
             color: "blue"
         }
    }
}

When I run this code I get all 3 three Rectangles with same widths. What am I doing wrong?

3 Rects same widths.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
WindCheck
  • 374
  • 1
  • 9
  • 1
    change `columnSpan` to `preferredWidth` – eyllanesc Feb 08 '21 at 16:10
  • The behavior is similar to QGridLayout: the span does not automatically indicate that a widget occupies more space, only that it occupies the space of two "cells" in the grid. Since no other reference is given for the layout (and there are not other objects in another row that singularly occupy the third and fourth cell), the three rectangles will occupy the same horizontal space. – musicamante Feb 08 '21 at 16:12

0 Answers0