[Qt-interest] Deleting the treewidget item

Ferenc Stelcz ferenc at stelcz.hu
Mon Jun 22 09:35:34 CEST 2009


Yuvaraj R wrote:
> Hi All
> 
> please parden me ,if my question is silly,,
> 
> 
> I added the items for QTreeWidget. using
> 
> QTreeWidgetItem *item  = new QTreeWidgetItem(ui->treeWidget);
> item->setText("cities");
> 
> QTreeWidgetItem *city1 = new QTreeWidgetItem(item);
> 
> city1->setText("Bangalore");
>  QTreeWidgetItem *city2 = new QTreeWidgetItem(item);
> 
> city1->setText("Chennai");
> 
> How do delete the child item and item..
> 
> 
> Any Idea..
> 
> 
> Advance Thanks for helpings...
> 
> 

//This will remove all the children of *item*
//Be warned, that the child items won't be deleted!
for(int childcount=0; i<item->childCount(); ++i)
{
	QTreeWidgetItem *currentChildItem = item->child(i);
	item->removeChild(currentChildItem);

	/*
		delete currentChildItem;
		currentChildItem = 0;
	*/
}

//This piece tries to remove *item*
QTreeWidgetItem *rootItem = item->parent(); //We get the parent of item
rootItem->removeChild(item); //Then remove item

HTH

--
Ferenc Stelcz
Junior Software Engineer

Banyan Technologies LLC.


__________ Information from ESET Smart Security, version of virus signature database 4175 (20090621) __________

The message was checked by ESET Smart Security.

http://www.eset.com





More information about the Qt-interest-old mailing list