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. QML Changing a model for a GridView in a state change with PropertyChanges

QML Changing a model for a GridView in a state change with PropertyChanges

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 2.6k Views 1 Watching
  • 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.
  • R Offline
    R Offline
    rafagomez89
    wrote on last edited by
    #1

    Hello, I'm trying to change dynamically a model for a GridView in a QML project. The GridView feeds from a XmlListModel that changes depending on a self-defined property called 'tags'. I've tried to implement it by a state change in this way:

    Code for the GridView:
    @ GridView{
    x:10; y:10
    id:menuUpperPart
    model:MainMenuModel{tags: "full"; place: "up"}
    delegate: MenuDelegate{}
    width: parent.width; height:Math.floor((menuUpperPart.count+1)/2)*80; cellWidth: 90; cellHeight: 90;
    focus:true; interactive: false
    }
    @

    State definition:
    @states:[
    State{
    name:'expanded'
    PropertyChanges{target: menuUpperPart; model: MainMenuModel{tags: Math.floor(index/2).toString(); place: "dwn"}}
    }
    ]
    @

    XmlListView definition:
    @XmlListModel {
    property string tags : ""
    property string place: ""

    source: "other/"+tags+"_"+place+".xml"
    query: "/feed/opcion"
    //namespaceDeclarations: "declare default element namespace 'http://www.w3.org/2005/Atom';"
    
    XmlRole { name: "name"; query: "nombre/string()" }
    XmlRole { name: "icon"; query: "icono/string()" }
    //XmlRole { name: "hq"; query: "link[@rel='enclosure']/@href/string()" }
    

    }@

    This gives me the following error:

    bq. PropertyChanges does not support creating state-specific objects.
    PropertyChanges{target: menuLowerPart; model: MainMenuModel{tags: Math.floor(index/2).toString(); place: "dwn"}}

    Does anyone know how could I implement the same functionality or solve this problem? Thanks!!

    1 Reply Last reply
    0
    • U Offline
      U Offline
      unai_i
      wrote on last edited by
      #2

      You could create both models in your QML file and reference to the appropriate one via the id of the object in your property changes.
      You may also want to load models through a loader if you don't want too much models loaded at the same time.

      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