[Interest] Awkwardness of delegates in heterogenous ListViews

Elvis Stansvik elvstone at gmail.com
Wed Jun 8 17:49:16 CEST 2016


2016-06-08 15:41 GMT+02:00 Kristoffersen, Even (NO14) <
Even.Kristoffersen at honeywell.com>:
> Have you tried something like this in the delegate?
>
> property alias some_descriptive_name: parent

It seems it's not allowed to use parent as the target of an alias (?):

file:///home/estan/qte/qte/qml/ItemDelegate.qml:5 Invalid alias reference.
Unable to find id "parent"

And this would still tie my "subdelegates" to this structure. They could
not be reused in other places, where lists are homogenous and I'm not using
the Loader approach.

But I guess there's really no way to make a delegate that can be used in
both the "normal" situation and in the indirect-through-Loader approach.

Elvis

>
> (Not tested, just an idea)
>
> -Even
>
> -----Original Message-----
> From: Interest [mailto:interest-bounces+even.kristoffersen=
honeywell.com at qt-project.org] On Behalf Of Elvis Stansvik
> Sent: 8. juni 2016 15:34
> To: interest at qt-project.org Interest <interest at qt-project.org>
> Subject: Re: [Interest] Awkwardness of delegates in heterogenous ListViews
>
> 2016-06-08 15:32 GMT+02:00 Elvis Stansvik <elvstone at gmail.com>:
>> Hi all,
>>
>> I'm currently using a "type" role in my items and then a Loader as
>> delegate, to give a level of indirection and let me choose the actual
>> delegate based on the "type" of the item.
>>
>> This explains it better (from my ListView):
>>
>> delegate: Loader {
>> sourceComponent: {
>> switch (type) {
>> case "color":
>> return colorDelegate
>> case "flag":
>> return flagDelegate
>> ...
>> }
>> }
>>
>> Component {
>> id: colorDelegate
>>
>> ColorDelegate { }
>> }
>>
>> Component {
>> id: flagDelegate
>>
>> FlagDelegate { }
>> }
>>
>> ...
>> }
>>
>> What I don't like with this approach is that inside my delegates, e.g.
>> ColorDelegate.qml, I have to use parent.ListView.view.model to get a
>
> I should clarify: I have to use this notation since it is the parent (the
Loader) which is the real delegate and has the ListView attached properties.
>
> Elvis
>
>> reference to the model (needed for editing operations). The use of
>> "parent" here assumes a certain layout, but I see no other way :(
>>
>> How have others solved the issue of delegates for heterogenous lists?
>>
>> Best regards,
>> Elvis
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160608/478fbeb3/attachment.html>


More information about the Interest mailing list