[SailfishDevel] Accessing ListView model properties in section.delegate

Andrey Kozhevnikov coderusinbox at gmail.com
Mon Feb 2 18:05:21 UTC 2015


you can use only one property as section. You need to compose your 
section value inside model yourself.

02.02.2015 20:55, Александр Крылков пишет:
> I have delegate like this:
>
> section
> 		{
> 			property:  "groupingString"
> 			delegate:  Row
> 			{
> 				width:  parent.width
> 				Label
> 				{
> 					width:  parent.width
> 					x:  Theme.paddingMedium
> 					text:  artistName
> 					wrapMode:  Text.WordWrap
> 					color:  Theme.highlightColor
> 					font.pixelSize:  Theme.fontSizeLarge
> 				}
> 				Label
> 				{
> 					width:  parent.width
> 					x:  Theme.paddingMedium
> 					text:  "["  +  albumYear  +  "]  "  +  albumName
> 					wrapMode:  Text.WordWrap
> 					color:  Theme.secondaryColor
> 					font.pixelSize:  Theme.fontSizeTiny
> 				}
> 			}
> 		}
>
> So I want to display artist name on one line and the album name on the second line, they will be the same for all elements inside each group.
> So maybe I should then just split "section" inside delegate and display it?
>
>
> groupingString is item->GetArtistName() + "-" + item->GetAlbumName(); from C++ side
>
> -- 
> Best regards,
>   Alexandermailto:Alexander.Krylkov at gmail.com
> 02.02.2015 21:47, Lucien Xu пишет:
>> 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,
>>   Alexandermailto:Alexander.Krylkov at gmail.com  
>>
>>
>> _______________________________________________
>> SailfishOS.org Devel mailing list
>> To unsubscribe, please send a mail todevel-unsubscribe at lists.sailfishos.org
>> _______________________________________________
>> SailfishOS.org Devel mailing list
>> To unsubscribe, please send a mail todevel-unsubscribe at lists.sailfishos.org
>
>
>
> _______________________________________________
> SailfishOS.org Devel mailing list
> To unsubscribe, please send a mail to devel-unsubscribe at lists.sailfishos.org

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.sailfishos.org/pipermail/devel/attachments/20150202/5c7d68e5/attachment.html>


More information about the Devel mailing list