Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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:

    1. Reimplemented methods of QAbstractListModel:
    1. rowCount()
    2. headerData()
    3. data()
    4. flags()
    5. setData()
    6. mimeTypes()
    7. mimeData()
    8. dropMimeData()
    9. supportedDropActions()
    1. For a child of QListView I've implemented next settings:
    1. setAcceptDrops(true);
    2. setDragEnabled(true);
    3. setDragDropMode(QAbstractItemView::InternalMove);
    4. setDropIndicatorShown(true);
    5. setSelectionMode(QAbstractItemView::SingleSelection);
    6. 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.


Log in to reply