Get Repeater's child
-
you can, actually I figured it out) i found the following string in Repeater description:
Items instantiated by the Repeater are inserted, in order, as children of the Repeater's parentSo you can access the children like this:
@import Qt 4.7
Rectangle {
id: screen
width: 1024
height: 600Row{
id:container
Repeater{
model:3
delegate:Rectangle{
width:100
height:100
color:"red"
}}
}Component.onCompleted:container.children[1].color="black"
}
@it works!
-
Kxyu, it is exactly what I've searched for. Thank you for the solution.
Though I don't understand why the parent item doesn't keep its children amount. Maybe it should? It seems a bit awkward to retrieve children from a Row and get children number from a Repeater :)Nevertheless, the question is answered.
-
Well it keeps, as children is a List, and List does. But as far as I understand in QML it works like javascript array, so you can use it's length property. I don't know why, but it gives amount+1, still you can use it
-
Well the children array is 0-index. So 0 is the first child. However, a length property will be 1-index.
If you've already accounted for this, it could be that the 0th child is pre-populated (some hidden child?). I haven't tested this though. -
[quote author="Kxyu" date="1293186164"]Well it keeps, as children is a List, and List does. But as far as I understand in QML it works like javascript array, so you can use it's length property. I don't know why, but it gives amount+1, still you can use it
[/quote]
Interesting property it should be documented I believe. Because I didn't find any mentions about it neither in documentation nor in the IntelliSense in QtCreator. -
Just tested it: a Repeater is the rightful child of an Item that is why you have amount + 1 result. If you exclude Repeater from the item you will have an actual amount.
-
IntelliSense needs some updates. It's not mentioned in documentation probably because it isn't related to QML. Just as the Math.functions aren't mentioned. Basically, javascript works in QML.
-
But if the QML list is nothing more than JS list why there is not a single word about it? How can user find that he can use length property, for example, if he has no clue about a nature of a QML list?
-
[quote author="xsacha" date="1293190186"]IntelliSense needs some updates. It's not mentioned in documentation probably because it isn't related to QML. Just as the Math.functions aren't mentioned. Basically, javascript works in QML.[/quote]
well, that's correct, but I think it would be better, if list in QML had all QList members and worked the same way, not like javascript array
-
Thank you for this answer, was very helpful!