Results 1 to 2 of 2

Thread: add child a QTreeWidget

  1. #1
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    172
    Thanks
    39
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default add child a QTreeWidget

    Hello, i have to add a node in QTreeWidget.
    My QTreeWidget before this operation is:
    voice1
    voice2
    |__subvoice1

    i want to add a child to subvoice1:
    voice1
    voice2
    |__subvoice1
    |__ subsubvoice1

    this's the code:
    Qt Code:
    1. // disconnect signal
    2. ui.twmConfigtreeWidget->blockSignals ( true );
    3.  
    4. QList<QTreeWidgetItem *> connectionItemsList;
    5. QString nodeNameString;
    6.  
    7. nodeNameString = "voice2";
    8. connectionItemsList = ui.twmConfigtreeWidget->findItems( nodeNameString , Qt::MatchContains , 0 );
    9.  
    10. for ( int i = 0; i < connectionItemsList.size(); i++ )
    11. {
    12. QList<QTreeWidgetItem *> connectionsChildren = connectionItemsList.at( i )->takeChildren();
    13.  
    14. for ( int k = 0; k < connectionsChildren.size(); k++ )
    15. {
    16.  
    17. if ( connectionsChildren.at( i )->text( 0 ) == "subvoice1" )
    18. {
    19. QTreeWidgetItem * twmQTreeWidgetRDPNewConnection = new QTreeWidgetItem ();
    20. twmQTreeWidgetRDPNewConnection->setText( 0 , "subsubvoice1" );
    21. connectionsChildren.at( i )->insertChild( 0 , twmQTreeWidgetRDPNewConnection );
    22.  
    23. }
    24. }
    25. }
    26.  
    27. // connect signal
    28. ui.twmConfigtreeWidget->blockSignals ( false );
    To copy to clipboard, switch view to plain text mode 

    but it does not work...my tree is always the same...any hint?

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: add child a QTreeWidget

    Notice what QTreeWidgetItem::takeChildren() docs say. It will remove children from the tree. And later you attempt to add more children to items which were just removed...
    J-P Nurmi

Similar Threads

  1. QTreeWidget child index
    By merlvingian in forum Newbie
    Replies: 3
    Last Post: 9th July 2015, 04:40
  2. child label alignment problem
    By ht1 in forum Qt Programming
    Replies: 9
    Last Post: 21st November 2007, 20:50
  3. Replies: 14
    Last Post: 19th March 2007, 08:48
  4. QTreeWidget & QStyle::PE_IndicatorBranch
    By nakkore in forum Qt Programming
    Replies: 2
    Last Post: 16th November 2006, 21:51
  5. resizing a QTreeWidget
    By drhex in forum Qt Programming
    Replies: 6
    Last Post: 27th October 2006, 22:32

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.