我有带有选择模式的 QTreeView:SingleSelection ( selection modes )。
我想删除选定的项目。那么rowsAboutToBeRemoved()
调用函数并自动选择相邻项目,如 comment 中指定的那样: //单选模式下保证选中一个item
.
如何避免选择改变?
- 如何使删除后不选中任何项目?
- 如何选择已删除项的父项?
最佳答案
给定:
QTreeView view;
我们可以访问 QItemSelectionModel
临时实例和禁用信号:
QItemSelectionModel *selectModel = view.selectionModel();
selectModel->blockSignals(true);
//set the selection
selectModel->blockSignals(false);
快速查看源代码显示 Qt 将 QItemSelectionModel::currentChanged()
信号连接到 View 的 currentChanged()
插槽,这似乎是源代码你的麻烦。
关于c++ - 从 QTreeView 中删除项目时取消选择所有行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50877726/