Results 1 to 2 of 2

Thread: QTreeView Drag and Drop

  1. #1

    Default QTreeView Drag and Drop

    Hi,
    I have two tree views, side by side and I want to drag one item from one tree into the other. So far I have managed to get something working but my problem is that for the QModelIndex that I drag from Tree A, I want its internal pointer to be available in Tree B.

    So far the only way I can see to do it is put the pointer into a QByteArray in

    Qt Code:
    1. QMimeData *MyModel::mimeData(const QModelIndexList &indexes) const
    To copy to clipboard, switch view to plain text mode 

    and read it back out in

    Qt Code:
    1. bool MyModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
    2. int row, int column, const QModelIndex &parent)
    To copy to clipboard, switch view to plain text mode 

    Is this really the best way? Streaming pointers feels wrong.

    Thanks

  2. #2
    Join Date
    Sep 2009
    Location
    Aachen, Germany
    Posts
    60
    Thanks
    2
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeView Drag and Drop

    You could also have the two TreeViews communicate.

    When you start the drag you could save the modelIndex that would be dragged from the Tree. In the other Tree, when there is a drop, you could use QDropEvent::source() to test if the drag comes from the other treeWidget and then just take the saved modelIndex from it.

Similar Threads

  1. How to disable drag&drop: QTreeView?
    By mirluk in forum Newbie
    Replies: 1
    Last Post: 24th March 2011, 17:09
  2. QTreeView: Drag and Drop
    By laugusti in forum Newbie
    Replies: 7
    Last Post: 19th March 2010, 19:05
  3. Drag and drop in QTreeView
    By Valheru in forum Qt Programming
    Replies: 3
    Last Post: 27th July 2008, 09:36
  4. drag and drop from QTreeView
    By Untersander in forum Qt Programming
    Replies: 1
    Last Post: 10th April 2006, 09:00
  5. Drag & drop for QTreeView
    By yogeshm02 in forum Qt Programming
    Replies: 2
    Last Post: 30th January 2006, 14:32

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.