[Qt-qml] Accessing delegate instance based on model element
Adriano Rezende
adriano.rezende at openbossa.org
Fri Sep 3 22:31:14 CEST 2010
On Tue, Aug 31, 2010 at 2:40 PM, Alex <alexlordax+qt at gmail.com> wrote:
> On Tue, Aug 31, 2010 at 12:42 AM, <tapani.mikola at nokia.com> wrote:
>> On 08/31/2010 03:44 AM, ext Alex wrote:
>>
>> Hi all,
>>
>> I am instantiating a bunch of components inside a Repeater, based on a
>> ListModel. In some cases, I need to act (e.g., invoke a javascript
>> function) directly on the delegate of a particular model element. Is
>> there a way to access the delegate instance which corresponds to a
>> particular model element?
>>
>> Cheers,
>> Alex
>> you should be able to do:
>>
>> item.children[index-to-the-delegate-you-want-to-access].property-you-want-to-access
>>
Hi,
Instead of accessing the delegate directly, it's better to change it
through Model/View mechanism, using property bindings like below:
Item {
width: 400
height: 400
ListModel {
id: model
ListElement { color: "red" }
ListElement { color: "green" }
ListElement { color: "blue" }
}
Column {
Repeater {
model: model
Rectangle {
id: item
width: 50
height: 50
color: model.color
}
}
}
MouseArea {
anchors.fill: parent
onClicked: model.setProperty(1, "color", "gray");
}
}
Does it solve your problem?
Br,
Adriano
More information about the Qt-qml
mailing list