Things have been going well, but now that I'm loading in the data for another QTreeWidget I'm using I just wanted to check on the ownership of QTreeWidgetItems, for instance in the following example would I need to explicitly delete rootItem somewhere if I removed it from the QTreeWidget via ui.treeWidget->removeItemWidget(rootItem)? Or is it automatically deleted? And what happens to the children of rootItem when I remove it? Are they deleted automatically or do I need to delete them explicitly?
rootItem->setText(0, "Root Node");
rootItem->setData(0, Qt::UserRole, integerID);
ui.treeWidget->addTopLevelItem(rootItem);
QTreeWidgetItem* rootItem = new QTreeWidgetItem;
rootItem->setText(0, "Root Node");
rootItem->setData(0, Qt::UserRole, integerID);
ui.treeWidget->addTopLevelItem(rootItem);
To copy to clipboard, switch view to plain text mode
Edit:
I've been playing around with things and it would seem removeItemWidget doesn't actually remove anything
. The only way I seem to be able to remove the selected item is to do this:
if (ui.treeWidget->currentItem()->parent() != NULL)
{
ui.treeWidget->currentItem()->parent()->takeChild(ui.treeWidget->currentItem()->parent()->indexOfChild(ui.treeWidget->currentItem()));
}
if (ui.treeWidget->currentItem()->parent() != NULL)
{
ui.treeWidget->currentItem()->parent()->takeChild(ui.treeWidget->currentItem()->parent()->indexOfChild(ui.treeWidget->currentItem()));
}
To copy to clipboard, switch view to plain text mode
Surely there's a better way to remove an item from the QTreeWidget, this can't be what I need to do right?
Bookmarks