Important: Please read the Qt Code of Conduct -

How to change and update model of GridView dynamically?

  • Hi;
    I have a GridView:

    GridView {
      id: gridView
      model: 2
      delegate: Rectangle {
        id: rect
        width: 70
        height: 70
        MouseArea { anchors.fill: parent; onClicked: rect.visible = false }

    model of GridView is 2 at the moment. I have this QML file:

    Popup {
      id: popup
      background: Rectangle {
        width: 250
        height: 250
        color: 'red'
        Button {
          id: btn
          onClicked: {
            gridView.model = gridView.model * 2; // I changed model
            popup.close(); // Then I closed popup

    This popup is opening if visibles of all rectangles are false.
    I changed model of GridView but when popup closed, I can't see any on the screen. Because there is still GridView with its old model (and you remember, visibles of rectangles are false).
    I want when model of GridView changed, I saw new GridView with its new model. How can I do it? Thanks.

  • HI @Ibrahim
    There are many ways to do it.
    You might be creating MyGrid and MyPopup in some qml file. Use gird.gridView.model instead of gridView.model inside popup button onclick.

    property int girdSize: 2
    id: grid

Log in to reply