Hi, you can adjust QAbstractItemView::selectionMode to make it possible to select multiple items in a view.
To remove items, you could implement QAbstractItemModel::removeRows() more or less like this:
bool MyModel
::removeRows(int row,
int count,
const QModelIndex &parent
) {
// a sanity check
if (row < 0 || count <= 0 || (row + count) > rowCount(parent))
return false;
// inform model-view frame work about upcoming removal
// remove corresponding items from the internal data structure in here
// inform model-view frame work about finished removal
endRemoveRows();
// removal succeed
return true;
}
bool MyModel::removeRows(int row, int count, const QModelIndex &parent)
{
// a sanity check
if (row < 0 || count <= 0 || (row + count) > rowCount(parent))
return false;
// inform model-view frame work about upcoming removal
beginRemoveRows(QModelIndex(), row, row + count - 1);
// remove corresponding items from the internal data structure in here
// inform model-view frame work about finished removal
endRemoveRows();
// removal succeed
return true;
}
To copy to clipboard, switch view to plain text mode
Now removing a bunch of selected items is kind of problematic. You cannot just remove them in an arbitrary order from the model because removing a certain item might cause other indices to become invalid. The solution is to remove items in reverse order, from end to beginning.
Bookmarks