View Full Version : QTreeView model

30th April 2012, 10:32
I'm trying to get back into Qt after a long break. I'm trying to write a model for my QTreeView. It's for managing my music collection and whatnot. I have a tree item for the artist, album and track. The problem is trying to get those three items done correctly in my QAbstractItemModel. I only see entries for one tree item and nothing like mine. Any ideas, or examples for my situation?

1st May 2012, 14:50
Try reading this (http://doc.qt.nokia.com/4.7-snapshot/itemviews-simpletreemodel.html).

5th May 2012, 10:16
Not really helpful, as that only explains how to use one tree item, while I need one for multiple different tree items.

5th May 2012, 23:56
You need to create a custom model that wraps three different tree representations of your collection database. You switch among these three trees based on a top level model index:

model index 0,0 chooses the artist tree
model index 1,0 chooses the album tree
model index 2,0 chooses the track tree

Once you have chosen the correct tree based on the top-level parent of the model index you have been given as the argument (e.g. to the QAbstractItemModel::data() method), then retrieving the correct sub-tree entry simply means going down that sub-tree until you get to the right child.