Is there any way i can specify the role name accessible to the delegate of Repeaters and ListViews at run time? For instance i have the following GenericRepeater {} that I want to reuse. I have lot of QAbstractListModel derived classes in C++. Many of them have different rolenames and different number of roles (if they all had just one role I could have accessed it by mentioning modelData, but moment there are more than one, modelData is no longer provided by Repeaters/ListViews to their delegates).
Here is the Repeater code:
//GenericRepeater.qml
Column {
property alias m_refModel: objRepeater.model
Repeater {
id: objRepeater
delegate: Rectangle {
height: 40; width: 200
color: "#000000"
Text {
color: "#ffffff"
anchors.fill: parent
text: model.genericRole //-----(1) What can I write here
}
}
}
}
Column {
property alias m_refModel: objRepeater.model
Repeater {
id: objRepeater
delegate: Rectangle {
height: 40; width: 200
color: "#000000"
Text {
color: "#ffffff"
anchors.fill: parent
text: model.genericRole //-----(1) What can I write here
}
}
}
}
To copy to clipboard, switch view to plain text mode
I want to use it in many places as:
//SomeFile.qml
GenericRepeater { m_refModel: myCppClass0 }
GenericRepeater { m_refModel: myCppClass1 }
GenericRepeater { m_refModel: myCppClass0 }
GenericRepeater { m_refModel: myCppClass1 }
To copy to clipboard, switch view to plain text mode
//SomeOtherFile.qml
GenericRepeater { m_refModel: myCppClass2 }
GenericRepeater { m_refModel: myCppClass2 }
To copy to clipboard, switch view to plain text mode
where myCppClass<n> are objects of classes derived from QAbstractListModel and each of those classes can have any number of roles each arbitarily named. Ofcourse the code will fail at (1) above. How do I use GenericRepeater in SomeFile.qml etc ? Just like I assign various models to GenericRepeater {} can I assign the roles too ? If no, then is there an alternate way to realize this ?
Bookmarks