QML ListView multiple delegates
-
Greetings Qt Devs,
I'm using a ListView. Is it possible to specify multiple delegates based on what the model item contains ?
For instance:
- if my item has a parameter containing "green" I specify a green Rectangle delegate item.
- If my item has a parameter containing "string" I specify a Text delegate item.
Thanks.
-
I think you'll need to make a single delegate that conditionally changes the visible property of its child items depending upon the values in the model. A single view can only create a single type of delegate as far as I am aware.
-
Loader with a condition on the source could also be used, but the performance will for sure drop quite a lot.
-
Hi bunjee,
Take a look at this: "http://cdumez.blogspot.com/2010/11/heterogeneous-list-model-in-qml.html":http://cdumez.blogspot.com/2010/11/heterogeneous-list-model-in-qml.html
I think this is what you are looking for.Regards,
wladek -
Thanks guys,
I thought about the "loading" condition. I guess the performance might hurt a bit.
Best current option is probably hiding / showing specific parts. Not the most elegant way.
Ideally I think this should be taken care of in C++. A multi delegate ListView could be a good idea to code.
-
Hi bunjee,
From my experience I can assure you that the "loading" condition is by far the better from performance point of view. I had a large delegate that defined all my widgets, and I did exactly as you said....hide/show specific parts. The interface suffered a "hung" effect, and after changing to the "Loader" it worked nicely.
You should try it yourself the both ways and see which one pleases you.
regards,
Wladek -
Hey Wladek,
Alright, I'll try your way ! Thanks for the code.
-
Looks like it's working pretty good.
I wonder if the Loader has some kind of cache under the hood to maximize performance.
Thanks.