View Full Version : Searching an example of beginMoveRows usage with extended selection

20th December 2009, 20:54

It's me again. Now that I know that the ModelTester is not compatible with beginMoveRows and now that I finally managed to figure how beginMoveRows works, I still have a question.

I have a QTableView with items that can be dragged to reorganize them. To do so I use beginMoveRows, which works perfectly when moving one item.

The problem is that my QTableView is setup to allow extended selection, so that the user can drag many non-contiguous items. So I have to execute beginMoveRows once for each item.

This "naive" solution clearly don't work since if you insert an item before the next one to be moved the row number will change, and the result will be a total mess of items...

I tried using QPersistentModelIndex, since the row is supposed to be updated on a move operation. I used one for the destination row

QPersistentModelIndex destinationIndex(index(row, 0, QModelIndex()));
(row is the parameter passed to the dropMimeData method)
and one for each item, created dynamically in the mimeData method.

Is this the right approach ? If yes, than do you know a example of moving non-contiguous items using beginMoveRows ?

Thanks for your answers.