Hi,

I'd like to sort items in a tree view by dragging and dropping.
My data is a flat list of rows and columns with no heirarchy. I chose not to use TableView as the row headers cant be hidden, is this right ?

I've got as far as subclassing standardItemView and re implementing :
supportedDropActions() const
removeRows(int row, int count, const QModelIndex &parent)

My trouble is what to put in removeRows so that a MoveAction is done on the model. At the moment I get copying of data in the view.

Another problem is that when dragging the treeView item, I get a row with a + as its a treeView Im using, any ideas where I'm going wrong.

Below is what I've got so far


Qt Code:
  1. MyModel::MyModel(QObject *parent)
  2. {
  3. }
  4.  
  5. Qt::DropActions MyModel::supportedDropActions() const
  6. {
  7. return Qt::MoveAction;
  8. }
  9.  
  10. bool MyModel::removeRows(int row, int count, const QModelIndex &parent)
  11. {
  12. if (parent.isValid())
  13. return false;
  14. beginRemoveRows(parent, 0, 0);
  15. // What am I doing here?
  16. endRemoveRows();
  17. return true;
  18. }
To copy to clipboard, switch view to plain text mode