PDA

View Full Version : Derived dropMimeData never called



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

ImperialPenguin
18th August 2012, 03:49
Did you ever figure this out? I'm having the exact same problem. The funny thing is, it was working a month ago. I don't think I changed anything in those two files, but when I tried it just now it didn't work. I did upgrade from Qt 4.5 to Qt 4.8, but I don't think that would break it.

Edit: Actually, my problem isn't identical. It's mimeTypes that is getting called when an object is dragged. mimeData never gets called.