javascript - How to add items to a QML Grid after creation? -
i've done bit of searching i've failed find answer must simple hasn't warranted question far. anyway i'm new qml , struggling find way add items grid dynamically post-creation.
basically have flickable grid inside containing (by default) 4 instances of custom class named imagetile, , when mousearea detects there's click wants add 2 instances of imagetile grid.
here snippet of code:
flickable { anchors.fill: parent contentwidth: 400 contentheight: 800 clip: true mousearea { id: mousearea anchors.fill: parent onclicked: { /* add 2 imagetile imagegrid */ } } grid { id: imagegrid columns: 2 spacing: 2 repeater { model: 4 imagetile { } } } } as can see i'm wondering should put inside onclicked event achieve adding 2 new instances of imagetile imagegrid.
thanks in advance help!
so being pushed in right direction mrericsir i've figured issue out.
first had specify proper data model repeater use, , assign delegate function convert information in data model actual qml elements. appending data model automatically triggered repeater execute delegate function.
flickable { anchors.fill: parent contentwidth: 400 contentheight: 800 clip: true listmodel { id: imagemodel listelement { _id: "tile0" } listelement { _id: "tile1" } listelement { _id: "tile2" } listelement { _id: "tile3" } } mousearea { id: mousearea anchors.fill: parent onclicked: { imagemodel.append({ _id: "tile" + imagemodel.count }) } } grid { id: imagegrid columns: 2 spacing: 2 repeater { model: imagemodel delegate: imagetile { id: _id } } } }
Comments
Post a Comment