kaa
kaa

Reputation: 1367

How to update selection in the QTableView after drag row

I have custom QTableView class that shows content of custom model based on QAbstractItemModel. In the model I've implemented all needed methods to support changing rows order by DragAndDrop ( using dropMimeData()).

But I do not know how to update selection in the view after model (and view) changed. For example: user clicks on the row, it becomes 'selected'; user drags this row to other place;
rows are swaps in the model and view;

BUT selection stays on the first selected row.

How model can notify view to change selection?

NOTE: I cant to create additional signals and slots because don't use MOC.

Upvotes: 0

Views: 762

Answers (1)

kaa
kaa

Reputation: 1367

The solution is:

  1. In function dropMimeData() need to use beginMoveRows() and andMoveRows() around place where data changed.
  2. Need to process signal QAbstractItemModel::rowsMoved of the model, where we can retrieve index of the target row.

Upvotes: 0

Related Questions