在运行时访问ListItemComponents [英] Accessing ListItemComponents on the run
问题描述
现在我正在尝试创建一个使用自定义QML加载dataModel的ListView.这是我的代码段:
right now I'm trying to create a ListView which loads the dataModel using a custom QML. Here's the snippet of my code:
ListView {
id: firstPageListView
visible: false
dataModel: firstPageDataModel
layout: GridListLayout {
columnCount: 1
cellAspectRatio: 2.0
headerMode: ListHeaderMode.Standard
verticalCellSpacing: 10
}
listItemComponents: [
ListItemComponent {
//custom qml that will be used
ThumbNote {
title: ListItemData.title
text: ListItemData.text
imageSource: ListItemData.image
listmode: true //list mode
date: ListItemData.date
}
}
]
}
我想创建一个将每个组件的listmode
属性更改为false
的按钮.这样,对象将调用在ThumbNote QML的onListModeChanged()
中设置的功能.
I want to create a button that will change the listmode
property of each component into false
. By doing so, the object will invoke a function that set in the onListModeChanged()
of the ThumbNote QML.
对不起,我的英语不好,我们将不胜感激. :)
Sorry for my poor english, any help would be appreciated. :)
推荐答案
也许您可能考虑将属性添加到ListView并将ThumbNotes的属性绑定到它.
Perhaps you might consider adding a property to the ListView and binding the ThumbNotes' properties to it.
例如:
ListView {
id: firstPageListView
visible: true
dataModel: firstPageDataModel
property bool listMode: true
...
listItemComponents: [
ListItemComponent {
//custom qml that will be used
ThumbNote {
title: ListItemData.title
text: ListItemData.text
imageSource: ListItemData.image
listmode: firstPageListView.listMode
date: ListItemData.date
}
}
]
}
Button {
onClicked: {
firstPageListView.listMode = false;
}
}
这篇关于在运行时访问ListItemComponents的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!