How to know "y" property of an Item when it is created in a ListView
Solved
QML and Qt Quick
-
I use a
ListView
and I need to fill my Window with the lastItem
that was inserted inside it.
In this case, I set theListView
property:contentY
with they
value of myItem
My problem is that when you insert a new Item, I don't know how to know the
y
value of the Item because it is not yet set.This is what I try:
ScrollView { id: scroll ListView { model: DelegateModel { id: visualModel model: myModel //Model is set in the cpp delegate: Rectangle { id: rectangleDelegate Component.onCompleted: { rectangleDelegate.ListView.view.contentY = rectangleDelegate.y console.log(rectangleDelegate.y ) //Not set yet (y = 0) } Button { onClicked { rectangleDelegate.ListView.view.contentY = rectangleDelegate.y console.log(rectangleDelegate.y ) //Now it is ok (y = rightValue) } } } } } }
How could I proceed ?
-
Which item
addRoot
refers to? -
Thanks, now it's more clear.
Have you tried using positionViewAtIndex? Looks like just what might suit your needs.
-
Great, happy coding :-)