delegate a ListView
-
Hello,
I have in my main.qml :
Classification{
classifObject: classifModel ? classifModel.technologyClassificationModelList : null
height: 300
width: parent.widthanchors { left: parent.left ;}
}
and in my Classification.qml I have :
ListView{
id: idClassifModelproperty var classifObject width: parent.width height: parent.height model: classifObject clip: true orientation: ListView.Vertical verticalLayoutDirection: ListView.TopToBottom delegate: ListView { width: parent.width height: 50 model: classifObject.classifPrimaireList delegate: Rectangle{ height: 50 width: 150 Text { text: name font.pixelSize: 25 font.bold: true color: graphicIdentity.raspberry anchors.centerIn: parent } } }
but text: name does not work. Do you have an idea ?
thank you for your help
-
Hello,
I have in my main.qml :
Classification{
classifObject: classifModel ? classifModel.technologyClassificationModelList : null
height: 300
width: parent.widthanchors { left: parent.left ;}
}
and in my Classification.qml I have :
ListView{
id: idClassifModelproperty var classifObject width: parent.width height: parent.height model: classifObject clip: true orientation: ListView.Vertical verticalLayoutDirection: ListView.TopToBottom delegate: ListView { width: parent.width height: 50 model: classifObject.classifPrimaireList delegate: Rectangle{ height: 50 width: 150 Text { text: name font.pixelSize: 25 font.bold: true color: graphicIdentity.raspberry anchors.centerIn: parent } } }
but text: name does not work. Do you have an idea ?
thank you for your help
@cosmoff Have you tried to use model.<property_name> to avoid clashing between delegate properties and data model?
Like this:delegate: Rectangle{ height: 50 width: 150 Text { text: model.name font.pixelSize: 25 font.bold: true color: graphicIdentity.raspberry anchors.centerIn: parent } }
See http://doc.qt.io/qt-5/qtquick-modelviewsdata-modelview.html#models for more details;
-
@cosmoff Have you tried to use model.<property_name> to avoid clashing between delegate properties and data model?
Like this:delegate: Rectangle{ height: 50 width: 150 Text { text: model.name font.pixelSize: 25 font.bold: true color: graphicIdentity.raspberry anchors.centerIn: parent } }
See http://doc.qt.io/qt-5/qtquick-modelviewsdata-modelview.html#models for more details;
@KroMignon
I tryed but it does not work :( Is it possible to do a delegate of a ListView like I do? -
@KroMignon
I tryed but it does not work :( Is it possible to do a delegate of a ListView like I do?@cosmoff I think I have read too quickly your QML... Sorry.
I dont understand your QML code in Classification.
Is the model for the inner ListView a propertie from items in main model?
If yes, i would write it like this:ListView{ id: idClassifModel width: parent.width height: parent.height clip: true orientation: ListView.Vertical verticalLayoutDirection: ListView.TopToBottom delegate: ListView { width: parent.width height: 50 model: classifPrimaireList delegate: Rectangle{ height: 50 width: 150 Text { text: name font.pixelSize: 25 font.bold: true color: graphicIdentity.raspberry anchors.centerIn: parent } } } }
And for main.qml
Classification{ model: !!classifModel ? classifModel.technologyClassificationModelList : 0 height: 300 width: parent.width anchors { left: parent.left ;} }
-
Hi @cosmoff , i did not understand your model assignment,from what i understood i have modified a bit of your code please have look into it:-
Classification.qml
ListView{ id: idClassifModel property var classifObject width: parent.width height: parent.height model: classifObject clip: true orientation: ListView.Vertical verticalLayoutDirection: ListView.TopToBottom interactive: false spacing: 100 delegate: ListView { width: parent.width height: 50 model: classifObject interactive: true delegate: Rectangle{ height: 25 width: parent.width z:1 color: "yellow" border.color: "blue" Text { text: name font.pixelSize: 25 font.bold: true color: "pink" anchors.centerIn: parent } } }}
main.qml
ListModel { id: dummyModel ListElement { name: "0" } ListElement { name: "1" } } Classification{ anchors.fill: parent classifObject: dummyModel anchors { left: parent.left ;} }
-
I just put :
delegate: ListView {
width: parent.width
height: 50
model: classifPrimaireList
delegate: Rectangle{
height: 50
width: 150Text { text: name font.pixelSize: 25 font.bold: true color: graphicIdentity.raspberry anchors.centerIn: parent } } }
}
and it works !
thank a lot !