I am trying to change the delegate of qml listview from C++ but currently I stuck at how to change the alias which represents the delegate property.
Update on details: I have multiple delegates in separated qml files, in my application there are many screens, each screen will have different UI of listview, what I want is something like:
Pass delegate file name to C++ function >>> C++ function set delegate property of listView (or thing like that) >>> listview loads corresponding delegate.
My qml file looks like:
Item {
id: root
property alias listViewDelegate: listView.delegate
ListView{
id: listView
delegate: MyDelegate{} // I have MyDelegate.qml file, it's working well
model: listModel
}
// List model
MyListModel {
id: listModel
}
}
I tried to change listViewDelegate alias from C++ using setProperty() method but got no luck (error in fact).
qmlObj->setProperty("listViewDelegate", componentDelegate);
How to achieve this? Or anyone can suggest me the better method to achieve it? Thanks!