davsa
17th July 2012, 08:20
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:
tree_view->setSelectionMode(QAbstractItemView::ExtendedSelect ion);
// Enable drag and drop
tree_view->setDragEnabled(true);
tree_view->setAcceptDrops(true);
tree_view->setDropIndicatorShown(true);
tree_view->setDragDropMode(QAbstractItemView::DragDrop);
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;
QStringList mimeTypes() const;
QMimeData *mimeData(const QModelIndexList &indicies) const;
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
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
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:
tree_view->setSelectionMode(QAbstractItemView::ExtendedSelect ion);
// Enable drag and drop
tree_view->setDragEnabled(true);
tree_view->setAcceptDrops(true);
tree_view->setDropIndicatorShown(true);
tree_view->setDragDropMode(QAbstractItemView::DragDrop);
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;
QStringList mimeTypes() const;
QMimeData *mimeData(const QModelIndexList &indicies) const;
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
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