Hello,

I have a QStandardItemModel structure that I've set up to be displayed in a tree view. The first item of each record contains several children, with each child having multiple children of it's own.

Thus, the tree structure looks something like:

Top-Level Reccord 1
| ----> Record-level list 1
| ----> Record-level list 2
| ----> List-level item 1
| ----> List-level item 2
| ----> Record Level list 3
Top-Level Record 2
Top-Level Record 3
...

It's easiest to think of it as each record having several different lists of information, thus the first-level children described the list name / type, and the second level children are the list items.

What I want to do is create a proxy model that operates *only* on one set of second-level children (a model that manipulates list items directly).

For example, if I have a record with three lists, and I want to create a model that manages the items in the second list, I should be able to write something like:

Qt Code:
  1. MyListProxyModel listProxyModel();
  2. listProxyModel.setSourceModel (mainModel);
  3.  
  4. QStandardItem secondListItem = mainModel.item(0, 0)->child(1);
  5. QModelIndex secondListIndex = mainModel.indexFromItem (secondListItem);
  6.  
  7. listProxyModel.setRootIndex (secondListIndex);
  8.  
  9. qDebug() << "The second list has " << listProxyModel.rowCount() << " records...";
To copy to clipboard, switch view to plain text mode 

Output: "The second list has 2 records..." (assuming above example structure).

I can think of a way to implement this in a custom proxy model, but it's not a very appealing approach, and I'd rather not write a custom class to encapsulate this functionality if I don't have to.

Is there a reasonably clean way to go about accomplishing this?