Results 1 to 2 of 2

Thread: Child items are lost on drop

  1. #1
    Join Date
    Jun 2010
    Posts
    22
    Qt products
    Qt4
    Platforms
    Windows

    Default Child items are lost on drop

    I've run into a problem with QTreeView where child items are not being moved during a drop. It seems that reimplementing dragMoveEvent causes this to happen. It's supposed to read a user variable from the item being dragged and compare it to the item where it is going to be dropped. If they have the same value then it calls QTreeView's dragMoveEvent, otherwise it ignores the event. I'm doing this because Qt doesn't allow accepted mimeTypes to be set for each individual item (or does it?).

    Qt Code:
    1. void ResourceView::dragMoveEvent(QDragMoveEvent *event)
    2. {
    3. QModelIndex index = indexAt(event->pos());
    4.  
    5. QDataStream stream( &event->mimeData()->data("resource/index"), QIODevice::ReadOnly);
    6. int type;
    7. int parentType =-1;
    8.  
    9. int r, c;
    10.  
    11. QMap<int, QVariant> v;
    12. stream >> r >> c >> v;
    13.  
    14. parentType = index.data( Qt::UserRole+1).toInt();
    15. type = v[Qt::UserRole+1].toInt();
    16.  
    17. if (parentType == type)
    18. {
    19. QTreeView::dragMoveEvent( event);
    20. }
    21. else
    22. {
    23. event->ignore();
    24. }
    25. }
    To copy to clipboard, switch view to plain text mode 

    The child items are moved when I completely comment this out. On the other hand, if I call QTreeView::dragMoveEvent( event) alone with the other stuff commented out in the function the problem still persists. What could be the issue?

  2. #2
    Join Date
    Jun 2010
    Posts
    22
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Child items are lost on drop

    It seems like the custom mime type I was using was causing the problem. Using the default mime type seem work. I'm just worried about foreign items being dragged in there.

Similar Threads

  1. Getting Child Items from QStandardItemModel
    By nikhilqt in forum Qt Programming
    Replies: 4
    Last Post: 4th June 2013, 15:10
  2. Replies: 1
    Last Post: 14th January 2012, 00:33
  3. Replies: 0
    Last Post: 15th April 2011, 19:04
  4. QTreeWidget: lost click after drag and drop
    By cresta in forum Qt Programming
    Replies: 12
    Last Post: 31st December 2010, 11:31
  5. QTreeWidget Infinity Child items
    By aekilic in forum Qt Programming
    Replies: 2
    Last Post: 1st June 2009, 13:19

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.