using Component in multiple Repeaters - how to identify Repeater from Component?
-
I hope the title makes sense. Here's a snippet of what I'm trying to do:
Column { Repeater { id: repeaterA model: c_plus_plus_function_that_returns_QList(ArgumentA) delegate: myComponent } Repeater { id: repeaterB model: c_plus_plus_function_that_returns_QList(ArgumentB) delegate: myComponent } Repeater { id: repeaterC model: c_plus_plus_function_that_returns_QList(ArgumentC) delegate: myComponent } } Component { id: myComponent Rectangle { visible: index < repeater.count // what to use for repeater here?
How can I uniquely identify the repeater from within the component? All I really need is the model size.
Thanks...
-
Try doing something like this.
import QtQuick Window { width: 640 height: 480 visible: true title: qsTr("Hello World") Component{ id : comp Rectangle { property var rep width: 150;height: 50;color:"blue" Text { id : t1 anchors.centerIn: parent text : rep.count } } } Column { width: parent.width/2 height: parent.height spacing: 3 id : c1 Repeater{ id : r1 model: 4 delegate: comp Component.onCompleted: { for(var i=0;i<4;i++) r1.itemAt(i).rep = r1 } } Repeater{ id : r2 model: 10 delegate: comp Component.onCompleted: { for(var i=0;i<10;i++) { r2.itemAt(i).rep = r2 r2.itemAt(i).color = "yellow" } } } } }
-
Nice. I simplified it a bit, passing only the count (not the entire repeater) to the Component, and it works just fine. Thanks!
import QtQuick Window { width: 640 height: 480 visible: true Component { id : component Rectangle { property int repeaterCount width: 150; height: 50; color: "blue" Text { id : t1 anchors.centerIn: parent text : repeaterCount } } } Column { Repeater { id : repeater1 model: 4 delegate: component Component.onCompleted: { for (var i = 0; i < repeater1.count; i++) { itemAt(i).repeaterCount = count } } } Repeater { id : repeater2 model: 10 delegate: component Component.onCompleted: { for (var i = 0; i < repeater2.count; i++) { itemAt(i).repeaterCount = count itemAt(i).color = "yellow" } } } } }
-
M mzimmers has marked this topic as solved on
-
Note that this only works if the model is static (doesn't change after the
onCompleted
).