[SOLVED] Fill GridLayout with Repeater



  • Dear Qt folks,

    I would like to fill a GridLayout by using a Repeater. This works as long as I have only one Element in the Repeater. However, if I am putting more than one element in the Repeater the layouting with GridLayout does not work anymore.

    @GridLayout {
    anchors.fill: parent
    columns: 4
    Repeater {
    model: 5
    Text { text: index }
    Text { text: "someting" }
    Text { text: "someting" }
    Text { text: "someting" }
    }
    }@

    Any suggestions how I can achieve my behaviour? Wrapping the elements inside the Repeater into an "Item" by itself does not solve the problem.

    Thanks in advance and with best regards,
    Markus



  • Hmm maybe i understand wrong what you want but the code works correct. It add 4 Text Elements in every column but every Text element on position 0,0. Maybe this is what you want:

    @
    GridLayout {
    columns: 4
    Repeater {
    model: 5
    Column {
    Text { text: index }
    Text { text: "someting" }
    Text { text: "someting" }
    Text { text: "someting" }
    }
    }
    }
    @



  • Thanks for your reply. What I want to achieve is to generate 5 rows in the GridLayout. So the contents of the Repeater element should be placed one-by-one in the columns. In the end I want to have a 4x5 Grid.

    Best regards,
    Markus



  • So it's solved right! Please add [SOLVED] to all your solved thread titles!



  • No it's not solved. So far I am getting the same result as if I would write

    @GridLayout {
    anchors.fill: parent
    columns: 4
    Repeater {
    model: 5
    Text { text: "someting" }
    }
    }@

    I can see only a 4x2 Grid containing 5 times the Text element. However, I would like to distribute all elements within the Repeater across the GridLayout.

    How can I achieve this?



  • Sorry i don't understand what you want :) Would you like to have a table like output? The GridLayout is not necessary for this and in my opinion the wrong element. Here another try hopefully it's what you want.
    @
    Column {
    Repeater {
    model: 5
    Row {
    spacing: 20
    Text { text: index }
    Text { text: "someting" }
    Text { text: "someting" }
    Text { text: "someting" }
    }
    }
    }
    @



  • Yes, you are right. A GridLayout somehow doesn't seem to work in this case. As I would like to fill my parent with the contents I have chosen a ColumnLayout now instead of a Column:

    @ColumnLayout {
    anchors.fill: parent
    Repeater {
    model: 5
    Row {
    spacing: 20
    Text { text: index }
    Text { text: "someting" }
    Text { text: "someting" }
    Text { text: "someting" }
    }
    }
    }@

    This seems to be doing what I want. Thanks for help and being patient. ;-)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.