Results 1 to 7 of 7

Thread: QStandardItem question.

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

    Default QStandardItem question.

    I have a QStandardItemModel, I have some parent and some childs in the model.
    Qt Code:
    1. child = self.model.item(parent).child(0)
    To copy to clipboard, switch view to plain text mode 
    This will give me the first child if the parent. The question is: How can I get the next child of parent?

    Thanks

  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: QStandardItem question.

    Eeem...

    python Code:
    1. child = self.model.item(parent).child(1)
    To copy to clipboard, switch view to plain text mode 
    ?

    Actually it's probably better to do it like this:
    python Code:
    1. QModelIndex firstChild = self.model.index(0, 0, parent)
    2. QModelIndex secondChild = self.model.index(1, 0, parent)
    3. QStandardItem firstItem = self.model.itemFromIndex(firstChild)
    4. QStandardItem secondItem = self.model.itemFromIndex(secondChild)
    To copy to clipboard, switch view to plain text mode 
    etc.
    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
    Jul 2009
    Location
    Valladolid, Spain
    Posts
    125
    Thanks
    16
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QStandardItem question.

    Why did you changed the child(0) to child(1) ? Isn't child(0) the first element under parent?

    I mean:

    |-parent0
    --child0
    --child1
    --child2
    |-parent1
    --child0
    |-parent2
    .............

    I can't say how many parents/childs I'll have, so I can't use your method. I just need to be able to see if there is a "next" child in the current parent. Something like being in "parent0, child1" and ask for "next" child, then I'll get "parent0, child2". If I'm in "parent1, child0" and I ask for next child, I'll get None, null, 0 or somehing like that...

    Is there any way of doing that?

  4. #4
    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: QStandardItem question.

    Quote Originally Posted by alexandernst View Post
    I can't say how many parents/childs I'll have, so I can't use your method.
    Qt is shipped with a very good documentation: Dare using it! -> QStandardItem::rowCount()

    P.s.: And next time please also mind to use the Newbie section for questions like that

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

    Default Re: QStandardItem question.

    Ok, I could use a temp int and count the number of childs in every parent and then I'll just go to child(int), but what about parents? How can I go to the next parent?

  6. #6
    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: QStandardItem question.

    Quote Originally Posted by alexandernst View Post
    Why did you changed the child(0) to child(1) ?
    Because you wanted to access the second child. At least that's what I understood.

    I can't say how many parents/childs I'll have, so I can't use your method.
    Hmm? Why not?

    I just need to be able to see if there is a "next" child in the current parent.
    Ok, if a parent has four children and your at the second one, it is easy to deduce how many more are left. Furthermore if you access a non-existant element, you'll get an invalid index - so even if you didn't know about the QAbstractItemModel::rowCount() method you could still know if you've just fallen off the cliff.

    BTW. Note also the QModelIndex::sibling() method.
    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.


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

    Default Re: QStandardItem question.

    Ok, I made it
    I just did something like

    parent = model.item(n_parent) (while n_parent gets incremented in a while)

    Oh, wysota, I meant "go to the next element", but without knowing the current one. But nm, I think I found a solution ^^

Similar Threads

  1. licensing question
    By tommy in forum Installation and Deployment
    Replies: 4
    Last Post: 14th April 2010, 11:54
  2. Question on checkable QStandardItem in QTreeView
    By ttvo in forum Qt Programming
    Replies: 1
    Last Post: 3rd April 2009, 00:30
  3. Subclassing QStandardItem
    By aLiNuSh in forum Newbie
    Replies: 4
    Last Post: 5th April 2007, 20:00
  4. Question regarding how to paint after zoom.
    By JonathanForQT4 in forum Qt Programming
    Replies: 2
    Last Post: 26th January 2007, 15:34

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.