PDA

View Full Version : QTableView Drag to change item order not working



Marlon Smith
29th August 2012, 19:44
Hi everyone,

I've created a QTableView and a custom model based on QAbstractTableModel to display a table with selectable rows. Using a QSortFilterProxyModel, I can sort the data when the user clicks on a column heading.

I am trying to add a feature so that the user can click on a row and drag it to change its displayed position in the table view. I don't want to change the underlying model, just change the viewed order, similar to what happens when the data is sorted by column heading. Currently when I drag a row to a new position, that row does not move, but the row I dragged it onto is moved to the bottom of the list.

I've been looking through the documentation and it sounds like QTableView has some weird behaviour when the selection behaviour is SelectRows. It also looks like I may have to implement mimeData and dropMimeData, but this seems clunky and way overkill.

Has anyone else had any luck with this?

Thanks

Marlon