[Interest] Dropping data in a Item View class

Etienne Sandré-Chardonnal etienne.sandre at m4x.org
Thu Oct 16 10:46:36 CEST 2014


Dear all,

I cannot manage to enable dropping data into an Item View class.

Basically:
 - The model is a custom QAbstractItemView subclass, having a tree
structure. Column 1 is editable
 - The view is a standard QTreeView


I would like to drop data from another widget in the editable field (column
1 indices). I have somewhere else in the app a custom widget that accepts
the drop correctly using reimplemented dragEnterEvent and dropEvent, so the
dragging is likely to be set up correctly.

What I did on the view:
 - treeView->setAcceptDrops(true);
 - treeView->setDragDropMode(QAbstractItemView::DropOnly);
 - treeView->setDefaultDropAction(Qt::CopyAction);
 - treeView->setDragDropOverwriteMode(true);
 - treeView->setDropIndicatorShown(true);

What I did on the model:
 - In the reimplemented flags(), I return for column 1 : Qt::ItemIsEditable
| Qt::ItemIsDropEnabled | Qt::ItemIsEnabled | Qt::ItemIsSelectable.
 - I reimplemented setData, editing works.
 - I reimplemented dropMimeData. The mime type is "application/x-ocxml" but
this function is likely not in cause since the drag cursor never shows an
allowed drop
 - I reimplemented supportedDropActions, it returns Qt::CopyAction


Then, the drag cursor never turns to the "drop allowed" indicator, and
dropping always fails.
I tried reimplementing mimeTypes to return
QStringList("application/x-ocxml") but then the app crashes upon dragging.

Any idea how to implement this?

Thanks!

Etienne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20141016/fa57bbeb/attachment.html>


More information about the Interest mailing list