如何使品红色矩形比红色矩形短6倍?
GridLayout {
id: gridLayout
anchors.fill: parent
flow: GridLayout.TopToBottom
Rectangle {color: "magenta"
Layout.row: 0
Layout.column: 0
Layout.fillHeight: true
Layout.fillWidth: true
Layout.rowSpan: 1
}
Rectangle {
Layout.row: 0
Layout.column: 1
color: "red"
Layout.rowSpan: 6
Layout.fillHeight: true
Layout.fillWidth: true
}
}
答案 0 :(得分:0)
Layout.fillHeight
是问题所在;它试图尽可能高。而是将Layout.preferredHeight
设置为第一列的所需高度。此外,当您为每个Rectangle
指定行和列时,无需更改流程 - 使用Layout.alignment
从顶部填充:
GridLayout {
id: gridLayout
anchors.fill: parent
Rectangle {
Layout.row: 0
Layout.column: 0
Layout.fillWidth: true
Layout.preferredHeight: parent.height/6
Layout.alignment: Qt.AlignTop
color: "magenta"
}
Rectangle {
Layout.row: 0
Layout.column: 1
Layout.fillHeight: true
Layout.fillWidth: true
color: "red"
}
}