Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to change and update model of GridView dynamically?
Forum Updated to NodeBB v4.3 + New Features

How to change and update model of GridView dynamically?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 841 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    Ibrahim
    wrote on last edited by Ibrahim
    #1

    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.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      Tirupathi Korla
      wrote on last edited by Tirupathi Korla
      #2

      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
      }
      
      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved