在 ListView 中创建项目时如何知道项目的 "y" 属性
How to know "y" property of an Item when it is created in a ListView
我使用 ListView
和 我需要用插入其中的最后一个 Item
填充我的 Window。
在这种情况下,我将 ListView
属性: contentY
设置为我的 Item
的 y
值
我的问题是当你插入一个新的Item时,我不知道如何知道Item的y
值,因为它还没有设置 .
这是我的尝试:
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)
}
}
}
}
}
}
我该如何继续?
感谢@derM,这是一个有效的简单示例:
ScrollView {
id: scroll
ListView {
model: DelegateModel {
id: visualModel
model: myModel //Model is set in the cpp
delegate: Rectangle {
id: rectangleDelegate
onYchanged: {
rectangleDelegate.ListView.view.contentY = rectangleDelegate.y
}
}
}
}
}
我使用 ListView
和 我需要用插入其中的最后一个 Item
填充我的 Window。
在这种情况下,我将 ListView
属性: contentY
设置为我的 Item
y
值
我的问题是当你插入一个新的Item时,我不知道如何知道Item的y
值,因为它还没有设置 .
这是我的尝试:
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)
}
}
}
}
}
}
我该如何继续?
感谢@derM,这是一个有效的简单示例:
ScrollView {
id: scroll
ListView {
model: DelegateModel {
id: visualModel
model: myModel //Model is set in the cpp
delegate: Rectangle {
id: rectangleDelegate
onYchanged: {
rectangleDelegate.ListView.view.contentY = rectangleDelegate.y
}
}
}
}
}