Results 1 to 4 of 4

Thread: QTreeView + Custom QStandardItemModel + DnD = frustrutating

  1. #1
    Join Date
    Dec 2014
    Posts
    49
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5 PyQt3 PyQt4
    Platforms
    Windows

    Default QTreeView + Custom QStandardItemModel + DnD = frustrutating

    So i have a custom QTreeView and a custom QStandardItemModel and they are functioning well. I wanted to add in drag and drop to this, however, i have now encountered some frustration.

    I have re-implemented dragEnterEvent(), dragMoveEvent(), and dropEvent(). I can trace when an item starts dragging, and when i am ready to drop it. Now is where the problem occurs, dropMimeData() is never called within the custom QStandardItemModel.

    Within the dropEvent, i have verified that the item is being dragged properly. I wanted to implement dropMimeData() so that i could encode the QModelIndexList of selected indexes.

    Is there anything in particular i should be checking for ?

    I am using this as a tree for a scene hierarchy.

    A
    |_B
    |_C
    |_D

    where i want to drag C to A.

    thanks for any help or suggestions.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QTreeView + Custom QStandardItemModel + DnD = frustrutating

    If you have reimplemented QAbstractItemModel::canDropMimeData(), are you sure it is returning true when you want it to? Have you reimplemented QAbstractItemModel::mimeTypes() to support your custom mime type if the default is unsuitable? If so, have you also reimplemented the mimeData() and dropMimeData() methods to support your mime types?

    You might want to take a look at the Drag and Drop example programs.
    Last edited by d_stranz; 26th January 2015 at 20:57.

  3. #3
    Join Date
    Dec 2014
    Posts
    49
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5 PyQt3 PyQt4
    Platforms
    Windows

    Default Re: QTreeView + Custom QStandardItemModel + DnD = frustrutating

    i have looked at them

    i did not reimplement canDropMimeData() though, i will investigate that. other than that, i have the other methods mentioned with my custom mime type.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QTreeView + Custom QStandardItemModel + DnD = frustrutating

    You might have to customize canDropMimeData() to handle your custom mime type. The default implementation always returns true, but I am not sure if that is true only for the default mime type or for any type.

Similar Threads

  1. Replies: 2
    Last Post: 5th March 2014, 10:53
  2. QTreeView with QStandardItemModel
    By aekilic in forum Qt Programming
    Replies: 0
    Last Post: 16th February 2011, 09:11
  3. Replies: 3
    Last Post: 20th October 2010, 11:37
  4. QTreeView with QStandardItemModel
    By steg90 in forum Newbie
    Replies: 3
    Last Post: 16th May 2007, 09:28
  5. can't do a QTreeView with a QStandardItemModel
    By Nuria in forum Qt Programming
    Replies: 4
    Last Post: 27th July 2006, 00:41

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.