PySide QTreeview beginRemoveRows索引错误

时间:2017-02-09 08:12:49

标签: python qt pyqt

我使用QTreeView连接到代理模型QSortFilterProxyModel,该代理模型已连接到模型QAbstractItemModel

我正在努力去除当前索引的行。相反的是,它总会删除最后一行的兄弟。

例如,如果我想删除B,它将删除C代替:

A

---- B

---- C

我认为我的输入是正确的,所以我不知道为什么它会删除错误的索引。目前我删除行的代码如下所示:

index = tree_view.currentIndex() # Get the current index.

mapped_index = tree_view.proxy_model.mapToSource(tree_view.currentIndex()) # Get the proper index to work with.

tree_view.tree_model.beginRemoveRows(mapped_index.parent(), mapped_index.row(), mapped_index.row()) # Removes wrong index!

tree_view.tree_model.endRemoveRows()

同样尝试以这种方式删除它会产生相同的结果:

mapped_index = tree_view.proxy_model.mapToSource(tree_view.currentIndex())

tree_view.tree_model.rowsAboutToBeRemoved.emit(mapped_index.parent(), mapped_index.row(), mapped_index.row())

tree_view.tree_model.removeRow(mapped_index.row(), mapped_index.parent())

tree_view.tree_model.rowsRemoved.emit(mapped_index.parent(), mapped_index.row(), mapped_index.row())

0 个答案:

没有答案