Qml 子元素可以均匀地填充网格吗?

Qml 子元素可以均匀地填充网格吗?,qml,Qml,我想知道是否有可能在qml中创建一个元素网格,以完全均匀地填充网格/父元素的宽度和高度: Grid { columns: 2 Repeater { model: 4 Rectangle { width: /* ??? */ height: / * ??? */ } } } 我认为a必须在这里设置绝对值。使用anchors.fill:parent以及类似width:parent

我想知道是否有可能在qml中创建一个元素网格,以完全均匀地填充网格/父元素的宽度和高度:

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

我认为a必须在这里设置绝对值。使用
anchors.fill:parent
以及类似
width:parent.width/2

我想您忘记设置parent的(
Grid
元素)锚点了。您也可以始终通过元素的id引用元素

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