【发布时间】:2023-03-07 13:27:02
【问题描述】:
我有一个ColumnLayout,它的锚点设置为anchor.fill: parent,因此它已经设置了一个维度,这取决于它的父维度。
如何将Rectangles 添加到此ColumnLayout 中,并具有特定 从上到下的间距?
现在我有这个:
ColumnLayout {
anchors.fill: parent
spacing: 2
Rectangle {
height: 50
width: 50
color: "red"
}
Rectangle {
height: 50
width: 50
color: "green"
}
Rectangle {
height: 50
width: 50
color: "blue"
}
}
但不是让矩形从上到下间隔2,而是将Rectangles 均匀地布置在ColumnLayout 中。
一种解决方案是将第一个矩形锚定到父对象的顶部,然后将其余矩形一个接一个地锚定,但如果可能的话,我想避免这种情况。
【问题讨论】:
-
我相信这个问题的名称有点误导。对于那些希望为列中的特定项目超载
spacing的人,您可以替换spacing并改用Layout.margins(以及相关联的Layout.bottomMargin、Layout.topMargin等)。