Results 1 to 5 of 5

Thread: Obtain index of child's parent

  1. #1
    Join Date
    May 2008
    Location
    Spain
    Posts
    92
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Obtain index of child's parent

    Hello,

    I can obtain index of child and text of parent, but I am interesting to obtain index of both.
    Qt Code:
    1. QTreeWidgetItem *parent = myItem->parent();
    2. QString nameItem;
    3. int index;
    4.  
    5. index = parent->indexOfChild(ui->deviceTree->currentItem());
    6. nameItem = parent->text(indice);
    To copy to clipboard, switch view to plain text mode 

    any advice???
    Best regards

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Obtain index of child's parent

    well, to get the index of the parent, you must ask the grandparent, i.e. the parent of the parent, (or the QTreeWidget, if no grandparent exists)

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

    webquinty (11th May 2009)

  4. #3
    Join Date
    May 2008
    Location
    Spain
    Posts
    92
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Obtain index of child's parent

    Quote Originally Posted by caduel View Post
    well, to get the index of the parent, you must ask the grandparent, i.e. the parent of the parent, (or the QTreeWidget, if no grandparent exists)
    Any example to understand it???

    thank you very much.

  5. #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: Obtain index of child's parent

    Qt Code:
    1. QTreeWidgetItem *child = /*currentItem() or whatever*/;
    2. QTreeWidgetItem *parent = child->parent(); //check if valid
    3. QTreeWidgetItem *grandparent = parent->parent(); //check if valid
    4. int index_child = parent->indexOfChild(child);
    5. int index_parent = grandparent->indexOfChild(parent);
    To copy to clipboard, switch view to plain text mode 

  6. The following user says thank you to Lykurg for this useful post:

    webquinty (11th May 2009)

  7. #5
    Join Date
    May 2008
    Location
    Spain
    Posts
    92
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Obtain index of child's parent

    Quote Originally Posted by Lykurg View Post
    Qt Code:
    1. QTreeWidgetItem *child = /*currentItem() or whatever*/;
    2. QTreeWidgetItem *parent = child->parent(); //check if valid
    3. QTreeWidgetItem *grandparent = parent->parent(); //check if valid
    4. int index_child = parent->indexOfChild(child);
    5. int index_parent = grandparent->indexOfChild(parent);
    To copy to clipboard, switch view to plain text mode 
    Thank you very much, I did not understand what was grandparent.

    Best regards

Similar Threads

  1. QSql*Model + QTreeView : make a tree
    By punkypogo in forum Qt Programming
    Replies: 18
    Last Post: 24th October 2008, 19:14
  2. Drag & Drop when parent and childs accept drops?
    By gri in forum Qt Programming
    Replies: 0
    Last Post: 17th October 2008, 10:00
  3. Qtopia core 4.2.2 cross compile make error
    By smiyai18 in forum Installation and Deployment
    Replies: 2
    Last Post: 28th August 2007, 18:04

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.