Change property of all items in a Repeater at once?
-
I want blanket commands that modify a property of every item of the repeater. right now I have this javascript function that does the job:
@ function disable() {
for (var i = 0; i < theRepeater.model; i++) {
theRepeater.itemAt(i).state = "disabled"
}
}@But I am hoping for a single command that can change the state of every item in the repeater to disabled
-
Hi,
Create a property variable , and then bind that property to the state of the Item and then when you change that property variable the state of each item changes as well
-
[quote author="p3c0" date="1406786774"]Hi,
Create a property variable , and then bind that property to the state of the Item and then when you change that property variable the state of each item changes as well[/quote]
Could you provide an example? I'm not sure what you mean by a property that is bound to the state... isnt that what the state property is for? and where should i be creating this property variable?
-
Sure here it is,
@
Item {
width: 400
height: 200property string currentState: "" Repeater { id: repeater model: 5 Rectangle { id: rect x: index * 50 y: 0 width: 50 height: 50 color: '#'+Math.floor(Math.random()*16777215).toString(16) state: currentState states: State { name: "moved"; PropertyChanges { target: rect; y: 50 } } transitions: Transition { NumberAnimation { properties: "y"; easing.type: Easing.InOutQuad } } } } Button { text: "Click" y: 200-50 width: 80 height: 50 onClicked: { currentState="moved" } }
}
@Now here the property variable currentState is binded to state property of each Rectangle. And on click of button we assign a new value to the property currentState and thus on that change the state of each Rectangle gets affected too.
Hope this is what you expect ... -
This is an interesting example of QML usage, thanks. I can't use currently because each rectangle's state gets overridden and becomes individual so I have to go back through each one and reset it somehow. I want each item in the repeater to be independent, except in this one case.