c++ - QML ListView inside Repeater -
how can assign different models listview, inside repeater? did sketch (my actual project larger):
column { repeater { model: ["line1","line2","line3","line4"] rectangle { listview { model: ??? delegate: rectangle { text { text: somemodelproperty } } } } } } currently, solving idea copy-pasting 10 rectangles, each containing listview. in c++, have implemented 10 qlist<qobject*>, , each list "bounded" listview doing
qqmlcontext * example = engine.rootcontext(); example->setcontextproperty(modelname,qvariant::fromvalue(listobject)); i pretty sure there more intelligent way this, have started working qml few days ago, , can't figure out solution.
there catch, can't use id value list element, nor can nest list model inside list element, @ least not directly.
you can populate this:
item { id: models listmodel {/*...*/} listmodel {/*...*/} //... } listmodel { id: outermodel } function set() { (var = 0; < models.data.length; ++i) { outermodel.append({"model": models.data[i] /* , other stuff */}) } } or if prefer using c++ data, can add qobject* "model" property each of elements in list , set function, either in example above or ids inner models specify.
on second thought, might want use name instead of "model" because can't imagine qml happy model: model
update: try doing (assuming 10 models exposed m1 - m10 in qml)
property var submodels: [m1, m2, ... m10] then listview inside repeater delegate can:
listview { model: submodels[index] // ... } then assuming have 10 elements in repeater, model each list view selected array appropriate element index.
Comments
Post a Comment