Results 1 to 3 of 3

Thread: How Get model of a child item within QStandardItem

  1. #1
    Join Date
    Sep 2013
    Posts
    10
    Thanks
    1
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Question How Get model of a child item within QStandardItem

    Hi everyone,

    I'm quite new in Qt/QML so I still have to learn some basics. Here is my problem on my app.

    My app has 2 ListView in qml, my model is "exported" from c++ by setContextProperty. The model is herited from QStandardItemModel and is called StandardQmlModel
    My model is a 2 level model. Which means 1 "main" item can have children, and that's it.
    So 1 Listview has the model exported from c++,once 1 item is selected from the first listview, the 2nd listview display the children items.

    So, in c++ code I did this,

    Qt Code:
    1. QObject* StandardQmlModel::childModel(QVariant child_item) const
    2. {
    3. QModelIndex idx = child_item.value<QModelIndex>();
    4.  
    5. QStandardItem* itm = 0;
    6. if(idx.isValid())
    7. {
    8. itm = (QStandardItem*)this->itemFromIndex(idx);
    9. if(itm->hasChildren())
    10. {
    11.  
    12. return itm->child(0,0).model();
    13. }
    14. }
    15. return 0;
    16. }
    To copy to clipboard, switch view to plain text mode 

    but what I get with this code is the "main" model, or the same model as display in the first ListView.
    So my question is : How can I get the sub Model of an item in a view ?

    Many thanks
    Bounce

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How Get model of a child item within QStandardItem

    Use the VisualDataModel element and set the rootIndex property to the item which is the parent item of those items you wish to display in the view.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    bounce (3rd September 2013)

  4. #3
    Join Date
    Sep 2013
    Posts
    10
    Thanks
    1
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How Get model of a child item within QStandardItem

    Awesome ! Many thanks

Similar Threads

  1. Replies: 2
    Last Post: 22nd August 2013, 10:50
  2. Replies: 9
    Last Post: 14th February 2013, 19:39
  3. Using model indices in complex model item relationships
    By hackerNovitiate in forum Newbie
    Replies: 0
    Last Post: 29th June 2011, 14:30
  4. QT Model View - parent Item different from child
    By mromanuk in forum Qt Programming
    Replies: 2
    Last Post: 9th March 2011, 18:21
  5. Replies: 7
    Last Post: 3rd December 2010, 05:02

Tags for this Thread

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.