I’m trying to learn how to implement Drag and Drop to model/view settings in Qt. As an exercise, I attempted to do that to the Editable Tree Model example available at the Qt web site:
/* mainwindow.cpp -- THIS IS NOT ALL CHANGES -- See link above for all changes */ view->setSelectionMode(QAbstractItemView::SingleSelection); view->setDragEnabled(true); view->viewport()->setAcceptDrops(true); view->setDropIndicatorShown(true); view->setDragDropMode(QAbstractItemView::DragDrop);
However, this didn’t quite work. While I can drag and drop items, the copied item appears as blank. This can be seen in this screen capture, but the main screenshots are:
Note that the documentation describes the need to re-implement
dropMimeData for drag and drop functionality, which I did not. This is because, upon inspecting the source code for that class, I find that its default implementation should already work in copying items in drag and drop, since it uses the default
application/x-qabstractitemmodeldatalist MIME format and uses
setItemData for the inserted items.
What is wrong here? Is it the default
dropMimeData that’s not working, or something else?
Source: Windows Questions C++