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



  • 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!!



  • 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.


Log in to reply
 

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