[英]Delete row with children from QTreeView with QStandardItemModel
我试过了
ModelIndexList list = ui->treeView->selectionModel()->selectedRows();
uint size = list.size();
if (size>0) {
for (int i = size - 1; i >= 0; --i) {
QModelIndex index = proxyModel->mapToSource(list[i]);
standardItemModel->removeRow(index.row());
}
如果我选择根行,它将删除带有孩子的行。 如果我选择一些子树,则仅删除根目录,并在尝试再次删除成为根应用程序的子级后崩溃。
我在removeRow函数中缺少父参数。 正确的代码在这里:
ModelIndexList list = ui->treeView->selectionModel()->selectedRows();
uint size = list.size();
if (size>0) {
for (int i = size - 1; i >= 0; --i) {
QModelIndex index = proxyModel->mapToSource(list[i]);
standardItemModel->removeRow(index.row()
/*I was missing this -->*/ , index.parent());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.