[Interest] Dropping data in a Item View class
Etienne Sandré-Chardonnal
etienne.sandre at m4x.org
Thu Oct 16 11:36:39 CEST 2014
I just found out the issue. Implementing mimeTypes() was the solution (the
documentation for this function is quite obscure IMHO), but the
dragEnterEvent of the view was then calling flags() on the model with an
invalid index (col=row=-1, null pointer) which I did not properly handled
in flags() subclass.
Another question then : does View classes handle right mouse button
drag&drop? Normally, if several drop actions are possible, the usual
behavior is to popup a context menu with the possible actions (Copy, Move,
...) but it seems that even by adding several actions and dragging with
right mouse button does not trigger any menu. Is this implemented in View
Widgets?
Thanks,
Etienne
2014-10-16 10:46 GMT+02:00 Etienne Sandré-Chardonnal <etienne.sandre at m4x.org
>:
> 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/42322585/attachment.html>
More information about the Interest
mailing list