Remove item from QTableView by drag
Hi commuity,
I would like to achieve this behavior:
I select some items in my QTableView widget, keeping the left button pressed, I drag the items outside the view -> the items are deleted from the model.
Something similar to drag&drop but with the result that the items are removed instead of dropped onto another widget.
Sincerely
Re: Remove item from QTableView by drag
Sounds like a good way to get your users angry at you. Will this action come with an Undo feature? If not, what happens if the user grabs and drags the wrong item? How does she get it back?
Re: Remove item from QTableView by drag
It does not come with an Undo feature :)
Re: Remove item from QTableView by drag
Quote:
It does not come with an Undo feature
I think you will be sorry for that. It will be the first thing on the bug report list.
To implement this, I think you will need to set QAbstractItemView::setDragEnabled() to true when there are selected items and the left mouse button has been pressed but not released, and QAbstractItemView::setDragDropMode() to DragOnly. You will also need to return the QAbstractItemModel::flags() with the value Qt::ItemIsDragEnabled set. You probably also have to watch for a QDragLeaveEvent and then watch at the application level for a QDropEvent. I don't know what happens if the user drags the items out of the application entirely.
This will be even more complicated if you already have drag and drop enabled so the user can rearrange items in the view.
Frankly, this sounds like a whole lot of work for something that is really just a piece of UI fluff. You could easily accomplish the same thing simply by letting the user select items from the table and then pressing the delete key. And that would give you the opportunity to ask "Are you sure?" before the items are actually deleted.