PDA

View Full Version : add child a QTreeWidget



mattia
22nd February 2008, 09:17
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:


// disconnect signal
ui.twmConfigtreeWidget->blockSignals ( true );

QList<QTreeWidgetItem *> connectionItemsList;
QString nodeNameString;

nodeNameString = "voice2";
connectionItemsList = ui.twmConfigtreeWidget->findItems( nodeNameString , Qt::MatchContains , 0 );

for ( int i = 0; i < connectionItemsList.size(); i++ )
{
QList<QTreeWidgetItem *> connectionsChildren = connectionItemsList.at( i )->takeChildren();

for ( int k = 0; k < connectionsChildren.size(); k++ )
{

if ( connectionsChildren.at( i )->text( 0 ) == "subvoice1" )
{
QTreeWidgetItem * twmQTreeWidgetRDPNewConnection = new QTreeWidgetItem ();
twmQTreeWidgetRDPNewConnection->setText( 0 , "subsubvoice1" );
connectionsChildren.at( i )->insertChild( 0 , twmQTreeWidgetRDPNewConnection );

}
}
}

// connect signal
ui.twmConfigtreeWidget->blockSignals ( false );


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

jpn
22nd February 2008, 23:37
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...