Hi, hoping some people could help me with some drag and drop of mime data

I have a treeview and a standardItemModel I have subclassed.
I'd like to drag and drop within the view to sort the items.
And a line to indicate where would be perfect.

I've looked at this thread and I've picked up lots of ideas.
http://www.qtcentre.org/forum/f-qt-p...icon-2304.html

However I cant make it work.. spent a few days trying

If I implement only these :

Qt Code:
  1. void MyTreeView::dragMoveEvent (QDragMoveEvent *event)
  2. {
  3.  
  4. dropSite = event->answerRect ( );
  5. model_->emit_layoutChanged();
  6. }
  7.  
  8. void MyModel::emit_layoutChanged ( )
  9. {
  10. emit layoutChanged ( );
  11. }
  12.  
  13. void MyTreeView::paintEvent ( QPaintEvent* event )
  14. {
  15. QTreeView::paintEvent (event);
  16. QPainter painter ( viewport() );
  17. int x, y, w, h;
  18. dropSite.getRect ( &x, &y, &w, &h );
  19. painter.drawLine ( 0, y, width(), y );
  20. event->accept();
  21. }
To copy to clipboard, switch view to plain text mode 

I get a line drawn although it doesnt stick to between items and draws behind at all pixel positions. However Its not a mime data drag and drop and so its a floating icon type which I want to avoid.

Now, if I implement :


Qt Code:
  1. void MyTreeView::mousePressEvent(QMouseEvent *event)
  2. {
  3. QTreeView::mousePressEvent ( event );
  4. if (event->button() == Qt::LeftButton) {
  5. dragStartPosition = event->pos();
  6. }
  7. repaint();
  8. }
  9.  
  10. void MyTreeView::mouseMoveEvent(QMouseEvent *event)
  11. {
  12. if (!(event->buttons() & Qt::LeftButton))
  13. return;
  14. if ((event->pos() - dragStartPosition).manhattanLength()
  15. < QApplication::startDragDistance())
  16. return;
  17.  
  18. QByteArray encodedData;
  19. mimeData = new QMimeData;
  20. // Sample text type mime data - I will use mybe row index to pass data instead
  21. mimeData->setData("application/vnd.text.list", encodedData);
  22.  
  23. drag = new QDrag(this);
  24. drag->setMimeData(mimeData);
  25. dropAction = drag->start ( Qt::CopyAction | Qt::MoveAction );
  26. repaint();
  27. }
To copy to clipboard, switch view to plain text mode 

I get a mime type drag and drop which I want but I cannot drop it on the Treeview anywhere. I get the no entry sign

I have these turned on:

treeView->setDragEnabled(true);
treeView->setDropIndicatorShown(true);
treeView->setAcceptDrops(true);

I guess I need to implement something in here :
Qt Code:
  1. bool MyModel::dropMimeData ( const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent )
  2. {
  3. qDebug("dropMimeData");
  4. if (action == Qt::CopyAction) {
  5. return true;
  6. }
  7. else {
  8. return false;
  9. }
  10. }
To copy to clipboard, switch view to plain text mode 

but this never gets called when I drop.

What am I missing and any tips ? Mybe someone else find this useful.
Thanks,