How to change and update model of GridView dynamically?



  • Hi;
    I have a GridView:
    MyGrid.qml:

    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:
    MyPopup.qml:

    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
    Mygrid{
    id: grid
    
    }
    MyPopup{
    id:popup
    }
    

Log in to reply
 

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