Results 1 to 2 of 2

Thread: QTreeView QAbstractItemModel drag drop

  1. #1
    Join Date
    Apr 2011
    Posts
    195
    Thanks
    49
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default QTreeView QAbstractItemModel drag drop

    Hi I use a custom QTreeView and QAbstractItemModel and want to implement drag drop.

    I followed the docu and reimplemented the needed methods. I just want to achieve internal move of items within a parent. The problem is that I can't drop an item between other items. I just can drop an item on another item.

    There is no drop indicator between elements. What's wrong, please help me.

  2. #2
    Join Date
    Apr 2011
    Posts
    195
    Thanks
    49
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTreeView QAbstractItemModel drag drop

    Hi
    I can append the dragged item as sibling on my own in dropMimeData(). So it is not important that there is a dropindicator between the items...

    But I have another problem:
    My QMimeData Object contains the internalPointer of my the dragged item. And the internal pointer has a QDomNode member.

    So have all things I need. The parent-Node, the parent-Index, the child-Node, the childI-index, the sibling-index and subling-Node. In dropMimeData() I append the the dragged node with the following code:

    Qt Code:
    1. siblingNode.parentNode().removeChild(newNode);
    2. siblingNode.parentNode().insertAfter(newNode,siblingNode);
    To copy to clipboard, switch view to plain text mode 
    The underlaying xml doc is now correct, but the QAbstractItemModel doesn't update. I tried everything beginRemoveRows() and endRemoveRows(), beginInsertRows(), endInsertRows().
    I emit dataChanged() with the parent index, but nothing is updated.
    What I have to do? Do I have reimplement insertRows and removeRows. I read that this is not necessary if I remove and insert data by myself...

    thank you

Similar Threads

  1. Replies: 0
    Last Post: 2nd June 2010, 18:52
  2. QTreeView: Drag and Drop
    By laugusti in forum Newbie
    Replies: 7
    Last Post: 19th March 2010, 20:05
  3. Drag and drop in QTreeView
    By Valheru in forum Qt Programming
    Replies: 3
    Last Post: 27th July 2008, 10:36
  4. drag and drop from QTreeView
    By Untersander in forum Qt Programming
    Replies: 1
    Last Post: 10th April 2006, 10:00
  5. Drag & drop for QTreeView
    By yogeshm02 in forum Qt Programming
    Replies: 2
    Last Post: 30th January 2006, 15: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.