QTreeWidget* treeWidget = new QTreeWidget(parent); QTreeWidgetItem* rootItem = new QTreeWidgetItem(treeWidget); rootItem->setText(0, "Root"); QTreeWidgetItem* childItem = new QTreeWidgetItem(rootItem); childItem->setText(0, "Child"); rootItem->removeChild(childItem); // remove the child item from the root
QTreeWidgetItemIterator it(treeWidget); while (*it) { QTreeWidgetItem* item = (*it); if (item->text(0) == "Child") { item->parent()->removeChild(item); // remove the child item from its parent break; } ++it; }This example iterates through all the items in the `treeWidget` and finds the child item with the text "Child". The `removeChild()` method is used to remove the child item from its parent. Package/library: Qt Core.