PDA

View Full Version : Displaying a data structure with children in a view



themagician
24th February 2016, 16:36
I have a data structure like this:


struct List {
int32_t id {-1};
int32_t seen {0};
int32_t total {0};
int32_t lastModified {-1};
bool isFavorite {false};
bool isWatchlist {false};
bool isDislike {false};
QString name {};
QList<List> children {};
}

I load the data in a model derived from QAbstractListModel which is attached to a default QListView and a custom delegate then renders the List objects like this:

http://i.imgur.com/oP1N7UA.png

These lists can also have children. And those children can have other children. And each "level" should have some indentation compared to its parent. I'd like to render each list with the above delegate. What would be the easiest way to do this? I can change the data structure if needed.

anda_skoa
24th February 2016, 17:00
That sounds like you want a tree model and a tree view.

Cheers,
_