I have my QTreeView basically working like I want. The only issue is that when I remove a row from a leaf in the QTreeView.

If I have the node expanded when an row is removed it works fine. But when the node is collapsed when I remove the row the arrow next to the leaf is gone until I add a new row or something like that.

EDIT: It seems to not update the leaf's text and add the item when it is collapsed either.

Qt Code:
  1. void
  2. NickTreeModel::removeUser(Aki::NickTreeItem *item)
  3. {
  4. int row = -1;
  5. for (int i = 0; i < d->rootItem->childCount(); ++i) {
  6. QModelIndex idx = index(i, 0);
  7. Aki::NickTreeItem *categoryItem = d->rootItem->child(i);
  8. if ((row = categoryItem->indexOfChild(item)) != -1) {
  9. beginRemoveRows(idx, row, row);
  10. delete categoryItem->takeChild(row);
  11. endRemoveRows();
  12. reset();
  13. }
  14. }
  15. }
  16.  
  17. void
  18. NickTreeModel::removeUser(Aki::Irc::User *user)
  19. {
  20. int row = -1;
  21. for (int i = 0; i < d->rootItem->childCount(); ++i) {
  22. QModelIndex idx = index(i, 0);
  23. Aki::NickTreeItem *categoryItem = d->rootItem->child(i);
  24. if ((row = categoryItem->indexOfChild(user)) != -1) {
  25. beginRemoveRows(idx, row, row);
  26. delete categoryItem->takeChild(row);
  27. endRemoveRows();
  28. }
  29. }
  30. }
To copy to clipboard, switch view to plain text mode