Results 1 to 5 of 5

Thread: Getting Child Items from QStandardItemModel

  1. #1
    Join Date
    Jan 2008
    Location
    Bengaluru
    Posts
    144
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Wink Getting Child Items from QStandardItemModel

    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,

    Qt Code:
    1. +Parent1
    2. + Child10
    3. - Child11
    4. - GrandChild110
    5. - GrandChild111
    6. - GrandChild112
    7. +Parent2
    8. + Child20
    9. - Child21
    10. - GrandChild210
    11. - GrandChild211
    12. - GrandChild212
    13. +Parent3
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. + Child10
    2. - Child11
    3. - GrandChild110
    4. - GrandChild111
    5. - GrandChild112
    To copy to clipboard, switch view to plain text mode 

    Please let me know how it can be done.

    Thanks
    Nikhil

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Getting Child Items from QStandardItemModel

    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.

  3. #3
    Join Date
    Jan 2008
    Location
    Bengaluru
    Posts
    144
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Getting Child Items from QStandardItemModel

    Thanks Chris. I will look into it.

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

    Thanks.

  4. #4
    Join Date
    Jan 2008
    Location
    Bengaluru
    Posts
    144
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Getting Child Items from QStandardItemModel

    Hey!

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

  5. #5
    Join Date
    Mar 2012
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Getting Child Items from QStandardItemModel

    Hi,

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

Similar Threads

  1. Replies: 3
    Last Post: 19th November 2009, 14:10
  2. QTreeWidget Infinity Child items
    By aekilic in forum Qt Programming
    Replies: 2
    Last Post: 1st June 2009, 13:19
  3. Replies: 2
    Last Post: 24th August 2008, 14:42
  4. Replies: 2
    Last Post: 23rd July 2008, 17:48
  5. Problem inserting child items into a QAbstractItemModel
    By Valheru in forum Qt Programming
    Replies: 5
    Last Post: 14th October 2006, 18:35

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.