Accessing ListItemComponents on the run

时光总嘲笑我的痴心妄想 提交于 2019-12-24 09:38:51

问题


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

                    }
                }
            ]

        }

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. :)


回答1:


Perhaps you might consider adding a property to the ListView and binding the ThumbNotes' properties to it.

E.g.:

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; 
    }
}


来源:https://stackoverflow.com/questions/18375182/accessing-listitemcomponents-on-the-run

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!