QML GridLayout跨度

时间:2014-07-10 10:22:50

标签: layout qml

如何使品红色矩形比红色矩形短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
        }
    }

http://i.stack.imgur.com/nHfmB.gif

1 个答案:

答案 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"
    }
}