PDA

View Full Version : Getting Child Items from QStandardItemModel



nikhilqt
5th January 2010, 13:43
Hi Guys,

I have a QStandardItemModel. I need to get a Children QVariantList OR QStandardItemModel itself by giving an QModelIndex() of the parent.

For ex: A tree as below,


+Parent1
+ Child10
- Child11
- GrandChild110
- GrandChild111
- GrandChild112
+Parent2
+ Child20
- Child21
- GrandChild210
- GrandChild211
- GrandChild212
+Parent3

By giving the QModelIndex() of parent item "Parent1" I need to get a QVariantList or QStandardItemModel of the children Items of the
same. Like.


+ Child10
- Child11
- GrandChild110
- GrandChild111
- GrandChild112

Please let me know how it can be done.

Thanks
Nikhil

ChrisW67
6th January 2010, 00:12
This looks like a job for a proxy model. My knowledge level is not really good enough to rattle off an exact solution. Have a read of the QAbstractProxyModel documentation and a look at the browser demo's history handling models and this related QtLabs article (http://labs.trolltech.com/blogs/2008/03/25/advanced-example-of-modelview/).

nikhilqt
6th January 2010, 07:33
Thanks Chris. I will look into it.

Guys, Anybody who have done like this. Please help me out.

Thanks.

nikhilqt
7th January 2010, 21:02
Hey!

treeView->setRootIndex(...) will do the necessary. Thanks.

vrushalid
4th June 2013, 16:10
Hi,

I am also facing the similar issue, but I didnt get the usage of "treeView->setRootIndex(...)". Could you please explain more?