[SailfishDevel] Accessing ListView model properties in section.delegate
Lucien Xu
sfietkonstantin at free.fr
Mon Feb 2 15:47:42 UTC 2015
Hello Alexander,
This do not really make sense:
Taking your example from Qt docs, in the medium category, there will be the Dog and Cat. In the "medium" section, you will have two different "name" properties, that are "Dog" and "Cat". What to pick to render name + size ?
What would you like to do actually ?
Regards,
Lucien
----- Mail original -----
De: "Александр Крылков" <alexander.krylkov at gmail.com>
À: devel at lists.sailfishos.org
Envoyé: Lundi 2 Février 2015 16:36:53
Objet: [SailfishDevel] Accessing ListView model properties in section.delegate
Hello! how can I access ListView model propeties in it's section delegate?
Examples on internet is showing only how to access property specified in section.property field by "section"
For example: Rectangle { id : container width : 200 height : 250 ListModel { id : animalsModel ListElement { name : "Parrot" ; size : "Small" } ListElement { name : "Guinea pig" ; size : "Small" } ListElement { name : "Dog" ; size : "Medium" } ListElement { name : "Cat" ; size : "Medium" } ListElement { name : "Elephant" ; size : "Large" }
} // The delegate for each section header Component { id : sectionHeading Rectangle { width : container . width height : childrenRect . height color : "lightsteelblue" Text { text : section font .bold: true }
}
} ListView { anchors .fill: parent model : animalsModel delegate : Text { text : name } section .property: "size" section .criteria: ViewSection . FullString section .delegate: sectionHeading }
}
But i want to use other model fields, for example: Rectangle { id : container width : 200 height : 250 ListModel { id : animalsModel ListElement { name : "Parrot" ; size : "Small" } ListElement { name : "Guinea pig" ; size : "Small" } ListElement { name : "Dog" ; size : "Medium" } ListElement { name : "Cat" ; size : "Medium" } ListElement { name : "Elephant" ; size : "Large" }
} // The delegate for each section header Component { id : sectionHeading Rectangle { width : container . width height : childrenRect . height color : "lightsteelblue" Text { text : name + size font .bold: true } }
} ListView { anchors .fill: parent model : animalsModel delegate : Text { text : name } section .property: "size" section .criteria: ViewSection . FullString section .delegate: sectionHeading }
}
If I will do it like in example above I will get: ReferenceError: name is not defined --
Best regards,
Alexander mailto:Alexander.Krylkov at gmail.com
_______________________________________________
SailfishOS.org Devel mailing list
To unsubscribe, please send a mail to devel-unsubscribe at lists.sailfishos.org
More information about the Devel
mailing list