sschober
sschober

Reputation: 2101

Can child elements evenly fill Grid?

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

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

I think a have to set absolute values here. Using anchors.fill: parent won't work, as well as something like width: parent.width / 2.

Upvotes: 3

Views: 2302

Answers (1)

sergk
sergk

Reputation: 3631

I think you forgot to set parent's (Grid element) anchors. Also you can always reference an element by it' id.

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

Upvotes: 5

Related Questions