Can children evenly fill the grid?

I am wondering if it is possible to create a grid of elements in qml that completely and evenly fill the width and height of the grid / parent:

Grid {
    columns: 2
    Repeater {
        model: 4
        Rectangle {
            width: /* ??? */
            height: / * ??? */
        }
    }
}

I think that absolute values ​​need to be set here. Using anchors.fill: parentwill not work as well as something like width: parent.width / 2.

+3
source share
1 answer

I think you forgot to set the parent elements ( Grid). Also, you can always refer to an element by its identifier.

Grid {
    anchors.fill: parent
    columns: 2
    rows: 3
    Repeater {
        model: 6
        Rectangle {
            width: parent.width / parent.columns
            height: parent.height / parent.rows
        }
    }
}
+5
source

All Articles