what is the best way to delete all childWidgetItem of QTreeWidgetItem recursively?



  • what is the best way to delete all childWidgetItem of QTreeWidgetItem recursively?
    thank you!



  • @opengpu2

    void MainWindow::delItemInTree(QTreeWidgetItem *item) {
        if (item == 0) return;
        QTreeWidgetItem *itemAbove = ui->treeWidget->itemAbove(item);
        if (itemAbove == 0) return;
        QTreeWidgetItem *parent = item->parent();
        while (item->childCount() > 0) {
            QTreeWidgetItem *tmp = item->takeChild(0);
            tmp = 0;
            delete tmp;
        }
        int index = parent->indexOfChild(item);
        delete parent->takeChild(index);
    }
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.