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 ?
- 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.
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.
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.
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.
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.
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.