PDA

View Full Version : How to show the leaf nodes of a treemodel in a listview?



Michael_BJFU
10th May 2013, 13:02
now, I come across a problem.
1. I have a treeview and one treemodel(I use QStandardItemModel) correspondingly. The hierarchy may look like this:
A
-A1
—A11
—-A111
-A2
—A21
—A22
2. I have another view which is a listview.
And I want to show the corresponding leaf nodes under which the user clicked.
e.g. when the node A2 is clicked, the listview should show A21 and A22, and when A, it shows A111, A21 and A22.
Is there any solution to this problem?
And I use QSortFilterProxyModel and the function filterAcceptsRow, but it seams that when dealing with A2 that i return false, A21 and A22 wouldn’t be called by filterAcceptsRow() any more.
Please help me.

Santosh Reddy
10th May 2013, 13:22
e.g. when the node A2 is clicked, the listview should show A21 and A22, and when A, it shows A111, A21 and A22.
Your requirement is very strange, do you really want A111, A21 and A22 when A is clicked, what it the logic behind it?


And I use QSortFilterProxyModel
You better implement custom QAbstractProxyModel

wysota
10th May 2013, 13:30
now, I come across a problem.
1. I have a treeview and one treemodel(I use QStandardItemModel) correspondingly. The hierarchy may look like this:
A
-A1
—A11
—-A111
-A2
—A21
—A22
2. I have another view which is a listview.
And I want to show the corresponding leaf nodes under which the user clicked.
e.g. when the node A2 is clicked, the listview should show A21 and A22, and when A, it shows A111, A21 and A22.
Is there any solution to this problem?

Yes. You need a custom proxy model (not a QSortFilterProxyModel) that will scan your base model and assemble the proxy accordingly. I have done something like that once and it worked ok.

Michael_BJFU
10th May 2013, 15:34
Your requirement is very strange, do you really want A111, A21 and A22 when A is clicked, what it the logic behind it?

Just like in Visual Studio, when creating a new project, you can choose the global category on the left and choose the project type on right. 9024

Santosh Reddy
10th May 2013, 16:39
Just like in Visual Studio, when creating a new project, you can choose the global category on the left and choose the project type on right.Ahh, I get it.