Populate GridLayout with Repeater

前端 未结 3 1069
广开言路
广开言路 2021-01-01 04:07

I try to add cells to my GridLayout by using a Repeater. My data is stored in a model and containing two properties per element:

3条回答
  •  無奈伤痛
    2021-01-01 04:36

    You can use GridLayout.flow to specify in which order the cells should be filled, i.e. row- (GridLayout.LeftToRight) or column-wise (GridLayout.TopToBottom). Note that you should specify the number of rows when using GridLayout.TopToBottom.

    Using this solution, the (simplified) example of skypjack would become:

    import QtQuick 2.5
    import QtQuick.Window 2.2
    import QtQuick.Layouts 1.1
    import QtQuick.Controls 1.4
    
    Window {
        width: 600; height: 400; visible: true
    
        GridLayout {
            anchors.fill: parent
    
            % specify the flow and number of rows
            flow: GridLayout.TopToBottom
            rows: repeater.count
    
            Repeater {
                id: repeater
                model: [ "title1", "title2", "title3", "title4", "title5", "title6" ] // example model
                Label {
                    Layout.fillWidth: true
                    Layout.fillHeight: true
                    text: modelData
                }
            }
    
            Repeater {
                model: [ "value1", "value2", "value3", "value4", "value5", "value6" ]  // example model
                TextArea {
                    Layout.fillWidth: true
                    Layout.fillHeight: true
                    text: modelData
                }
            }
        }
    }
    

提交回复
热议问题