07-15-2013 11:41 AM - edited 07-15-2013 11:51 AM
(Please note that I am NOT using QML)
I would like to create a ListView with varying types of list items. Is there any way I can use more than one
QVariantListDataModel on a listview? I need different list view cells to show different data and probably be of different sizes. Is this possible?
07-15-2013 12:19 PM
One ListView can only display a single DataModel at a given time. However you can easily swap DataModels, if that is what you're after?
07-15-2013 12:27 PM - edited 07-15-2013 12:31 PM
Thanks for the reply!
No I don't think swapping is what I'm after, I would like a ListView where each item can potentially contain different types of content, different backgrounds and can be of different heights.
I am selecting from 4 or 5 different SQL tables, which are completely different but share one common field (IDNum), I would like to sort these by IDNum and have a ListView display them, where items of type A might show an image and a label, items of type B may show only 3 labels, items of type C may show two images and have a different background color. This is just an example.
How can I achieve this?
07-15-2013 12:47 PM
07-15-2013 01:20 PM - edited 07-15-2013 01:30 PM
Would you happen to have a link to an example of this? Or know of any sample apps that do this?
Right now I am doing the following:
list = reply.result().toList();
QVariantMap map = QVariantMap();
foreach (QVariant entry, list)
QVariantMap m = entry.toMap();
map["title"] = m["AirSegmentNumber"].toString();
map["image"] = QString("assets/icons/suitcase.png");
map["pnrid"] = m["PnrID"].toString();
Where myTripModel is of type bb::cascades::QVariantListDataModel. How would I go about adding items of different types??
07-15-2013 02:23 PM
Sure the List View documents such an example. In your DataModel you need to implement the following method:
Q_INVOKABLE QString itemType (const QVariantList &indexPath)
Based on this method the proper ListItemComponent you define gets selected.
07-15-2013 04:32 PM