Results 1 to 6 of 6

Thread: Drag and drop with QTreeWidget

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default Drag and drop with QTreeWidget

    Hi,

    I subclassed the code below from QTreeWidget to enable drag and drop. The problem is when i'm draging an item containing childrens, the childrens don't follow the parent on the drop. Is there a problem with mimeData?

    Also, is there a way to obtain the index of the parent where I make the drop?

    Thanks
    Qt Code:
    1. void QMyTreeWidget::mouseMoveEvent(QMouseEvent *event)
    2. {
    3. QModelIndexList liste=selectedIndexes();
    4. QMimeData *mimeData = model()->mimeData(liste);
    5. QDrag *drag = new QDrag(this);
    6. drag->setMimeData(mimeData);
    7. drag->setHotSpot(event->pos() - rect().topLeft());
    8. Qt::DropAction dropAction = drag->start( Qt::MoveAction);
    9. if (dropAction == Qt::MoveAction) {
    10. model()->removeRows(liste[0].row(),liste.size(),liste[0].parent());
    11. }
    12. }
    13.  
    14.  
    15. void QMyTreeWidget::dropEvent(QDropEvent *e)
    16. {
    17. QTreeWidget::dropEvent(e);
    18. e->setDropAction(Qt::MoveAction);
    19. e->accept();
    20. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacek; 6th February 2007 at 21:51. Reason: missing [code] tags

Similar Threads

  1. Drag & drop with model/view (Qt4)
    By yogeshm02 in forum Qt Programming
    Replies: 16
    Last Post: 19th September 2011, 20:36
  2. Drag and Drop
    By allensr in forum Qt Programming
    Replies: 1
    Last Post: 11th December 2006, 20:50
  3. Replies: 7
    Last Post: 8th September 2006, 16:19
  4. Drag and drop revisited
    By Big Duck in forum Newbie
    Replies: 2
    Last Post: 30th June 2006, 16:41
  5. Drag 'n Drop problem
    By kiker99 in forum Qt Programming
    Replies: 4
    Last Post: 16th January 2006, 16:35

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.