Re: Access delegate Property
You can use listt.itemAt() to access the delegate instance at any given index.
However, there is likely a more declarative way for whatever you are trying to do.
Can you explain what your goal is?
Cheers,
_
Re: Access delegate Property
Hi
i want to change the delegate property on button click.Here is my example:
Code:
Window {
visible: true
width: 360
height: 360
Button{
id: btn
anchors{right: parent.right;rightMargin: 50;top: parent.top;topMargin: 150}
width: 100
height: 50
text: "CLICK"
MouseArea{
anchors.fill: parent
onClicked: {
for(var j=0;j<3;j++)
{
listView.fruit_color[j] = "black" //Here i want to change the color of the text for all the 3 instances i have.If fruit colour is not an array it works fine.
}
}
}
}
Rectangle {
width: 200; height: 200
ListModel {
id: fruitModel
property string language: "en"
ListElement {
name: "Apple"
cost: 2.45
}
ListElement {
name: "Orange"
cost: 3.25
}
ListElement {
name: "Banana"
cost: 1.95
}
}
Component {
id: fruitDelegate
Row {
id: fruit
Text { text: " Fruit: " + name; color: fruit.ListView.view.fruit_color[index] }
Text { text: " Cost: $" + cost }
Text { text: " Language: " + fruit.ListView.view.model.language }
}
}
ListView {
id: listView
property var fruit_color: ["green","red","blue"]
model: fruitModel
delegate: fruitDelegate
anchors.fill: parent
}
}
Re: Access delegate Property
So additional to modifying the delegate as I've already pointed out you can
- Modify a copy of the array then assign to the property.
- Put the color into the model then modify the model.
- Or if the color is an override, have an override property and use it in a property binding for the Text's color so it takes precendece over the usual color
Oh, and use [code][/code] tags around code
Cheers,
_
P.S.: why a mouse area inside the button, doesn't the button already have a clicked signal?