PDA

View Full Version : Nested Models



Dan7
26th August 2015, 19:01
Hi everyone,
I'm using Qt4.8 and I need to make a model like the one in the attached picture: two parents, for both parent there is a set of childs with an associated table.

What I'd like to know is: it's possible to make it with a single model? If the answer is "Yes" how can I proceed? (link/tutorials are welcome)
Is there an alternative way to follow? for example: two treemodels, the first one for parent-child structure the second with tables, in which
all childs are linked to their table through a QMap

http://s16.postimg.org/kf8tjdhf5/esempio.jpg (http://postimg.org/image/kf8tjdhf5/)

d_stranz
26th August 2015, 20:31
Yes, it is possible with QAbstractItemModel-based model. For each level in your model, you will need to return the appropriate values for rowCount() (number of child rows for a given item) and columnCount() (number of cells in the child row). You will also need to pay close attention to the parent / child relationships when you implement these methods as well as data() / setData() and index().

Sorry, but I don't know of any examples, nor is there an out-of-the-box QAbstractItemView-derived class that can display such a model.