Results 1 to 8 of 8

Thread: QStandardItemModel, parents and childs

  1. #1
    Join Date
    Jul 2009
    Location
    Valladolid, Spain
    Posts
    125
    Thanks
    16
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QStandardItemModel, parents and childs

    How can I make this:

    |-parent0
    --child0
    --child1
    |-parent1

    The code for adding the parents is

    Qt Code:
    1. model.appendRow(QStandardItem("parent0"))
    2. model.appendRow(QStandardItem("parent1"))
    To copy to clipboard, switch view to plain text mode 

    and for the childs?

    I have this and I'm not sure that it's working:

    Qt Code:
    1. model.item(0).apprenRow(QStandardItem("child0"))
    To copy to clipboard, switch view to plain text mode 

    Thanks

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

    Default Re: QStandardItemModel, parents and childs

    What do you mean you are not sure if that's working? Can you see the child0 item or not?
    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. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QStandardItemModel, parents and childs

    Quote Originally Posted by alexandernst View Post
    and for the childs?

    I have this and I'm not sure that it's working:
    Hmm, if you are not sure, if it's working, why don't you simply try and see if it's working And beside, a look into the docs are always good:
    An example usage of QStandardItemModel to create a tree:
    Qt Code:
    1. QStandardItem *parentItem = model.invisibleRootItem();
    2. for (int i = 0; i < 4; ++i) {
    3. QStandardItem *item = new QStandardItem(QString("item %0").arg(i));
    4. parentItem->appendRow(item);
    5. parentItem = item;
    6. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jul 2009
    Location
    Valladolid, Spain
    Posts
    125
    Thanks
    16
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QStandardItemModel, parents and childs

    In fact, I'm trying to test it, but I cant see it
    And... my code is a little bit different.
    I have a QStandardItemModel with 5 columns per item. 2 and 3 column are ID's.

    Qt Code:
    1. item = self.__search_by_id(id) #this will return a QStandardItem matching the ID arg
    2. item.appendRow([None, None, QStandardItem(var), QStandardItem(var2), QStandardItem(True)])
    To copy to clipboard, switch view to plain text mode 

    I cant see the childs... Maybe I'm doing something wrong? (doc's says that everything is fine)

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

    Default Re: QStandardItemModel, parents and childs

    I'm not sure how appending a null would work... There should be 5 items here, some of them may be empty but they should still be there. And I think you need to tell the parent item that its children are to have 5 columns - it's not enough to do that on the top-level.
    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.


  6. #6
    Join Date
    Jul 2009
    Location
    Valladolid, Spain
    Posts
    125
    Thanks
    16
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QStandardItemModel, parents and childs

    Mmm, ok, so... how could I do that? could you give me an example or a link? (link != pyqt docs if possible, I already have that one xD)

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

    Default Re: QStandardItemModel, parents and childs

    To do what exactly? To set the column count of children to 5? QStandardItem::setColumnCount()
    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.


  8. #8
    Join Date
    Jul 2009
    Location
    Valladolid, Spain
    Posts
    125
    Thanks
    16
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QStandardItemModel, parents and childs

    nm, I did it

    It was just simple as

    child.appendRow([.....])

    But thanks anyway!

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.