Drag'n'Drop with QListView
-
Hello everyone! I have created 3 my own classes inheriting from QAbstractListModel, QListView and QItemDelegate which work together like MVC. I'm creating browser like view and I need to use a child of QAbstractItemView like a Drag'n'Drop widget, interacting with another applications. I've achieved realization of drag operation, but I'm not able to launch drop operation. What I have done:
- Reimplemented methods of QAbstractListModel:
- rowCount()
- headerData()
- data()
- flags()
- setData()
- mimeTypes()
- mimeData()
- dropMimeData()
- supportedDropActions()
- For a child of QListView I've implemented next settings:
- setAcceptDrops(true);
- setDragEnabled(true);
- setDragDropMode(QAbstractItemView::InternalMove);
- setDropIndicatorShown(true);
- setSelectionMode(QAbstractItemView::SingleSelection);
- setDragDropMode(QAbstractItemView::DragDrop);
Gave myself up to despair, I've reimplemented dragEnterEvent() for a child of QListView too (with use after QListView::dragEnterEvent(e)). It shows that MIME object comes to my widget and has correctly data. But no one call to drop-methods of a child of QAbstractListModel occurs.
Does anybody see a foolish thing in my actions?)
-
You might need to (re)implement draMoveEvent() and dropEvent() too. Depending on your use case, dragLeaveEvent() too.