QML GridLayout span

前端 未结 1 496
臣服心动
臣服心动 2021-02-10 15:48

How can I make the magenta rectangle to become 6 times shorter than the red rectangle?

    GridLayout {
        id: gridLayout
        anchors.fill: parent
              


        
相关标签:
1条回答
  • 2021-02-10 15:59

    The Layout.fillHeight is the problem; it tries to be as tall as possible. Instead, set Layout.preferredHeight to the desired height for the first column. Also, it is not necessary to change the flow when you specify the row and column for each Rectangle -- use Layout.alignment to fill from the top:

    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"
        }
    }
    
    0 讨论(0)
提交回复
热议问题