我已经搜索过QT文档供参考,但我有一些问题。 这里是QT文档的实现:如何在QT中为自定义模型实现removeRow()函数?
bool TableModel::removeRows(int position, int rows, const QModelIndex &index)
{
Q_UNUSED(index);
beginRemoveRows(QModelIndex(), position, position + rows - 1);
for (int row = 0; row < rows; ++row) {
listOfPairs.removeAt(position);
}
endRemoveRows();
return true;
}
我认为它在tableview中使用index.row直接定位在模型中的数据。但是如果我为tableview启用排序呢?排序后,tableview中的索引不对应于模型中的数据。 tableview中的第一行可能是模型中的第三个数据。
如何通过tableview查找模型中的数据? 是否有更好的实现removeRow()函数?