Hi,
I've followed the drag and drop documentation on how to implement drag and drop in a view. However, I can't get it to work.
I have a QWidget which has a QTreeView inside of it. On the QTreeView I set:
// Enable drag and drop
tree_view->setDragEnabled(true);
tree_view->setAcceptDrops(true);
tree_view->setDropIndicatorShown(true);
tree_view->setSelectionMode(QAbstractItemView::ExtendedSelection);
// Enable drag and drop
tree_view->setDragEnabled(true);
tree_view->setAcceptDrops(true);
tree_view->setDropIndicatorShown(true);
tree_view->setDragDropMode(QAbstractItemView::DragDrop);
To copy to clipboard, switch view to plain text mode
The tree view has a proxy model which has a source model that i've derived from QAbstractItemModel. In my derived model class I've implemented:
Qt
::ItemFlags flags
(const QModelIndex &index
) const // Returns Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsEnabled | Qt::ItemIsSelectable;Qt::DropActions supportedDragActions() const; // Returns Qt::CopyAction | Qt::MoveAction;
QMimeData *mimeData
(const QModelIndexList
&indicies
) const;
bool dropMimeData
(const QMimeData *data, Qt
::DropAction action,
int row,
int column,
const QModelIndex &parent
);
Qt::ItemFlags flags(const QModelIndex &index) const // Returns Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
Qt::DropActions supportedDragActions() const; // Returns Qt::CopyAction | Qt::MoveAction;
QStringList mimeTypes() const;
QMimeData *mimeData(const QModelIndexList &indicies) const;
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
To copy to clipboard, switch view to plain text mode
When I try to drag an item mimeData() gets called and seems to encode the data correctly. However, dropMimeData() is never called after that. When I attempt to drag an item, I never see any indicator either. I can't work out what is missing. Does anyone have any idea of what I'm missing?
Regards,
davsa
Bookmarks