Hi
i want to change the delegate property on button click.Here is my example:
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
}
}
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
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks