[Interest] Drag & Drop between QTreeWidgets
Thomas Sevaldrud
thomas at silentwings.no
Sat Feb 6 17:50:21 CET 2016
A little update; I made it work by overriding the dropMove() event and
accepting it. When I did this it works, regardless of the dragDropMode. Not
sure I understand how and why, but as long as it works, I guess I'm happy
:-)
On Sat, Feb 6, 2016 at 1:35 PM, Thomas Sevaldrud <thomas at silentwings.no>
wrote:
> Hi,
>
> In my application I have two QTreeWidgets, and I need to drag items from
> one of them to the other. I am not copying or moving actual
> QTreeWidgetItems, this operation simply indicates that I want to add an
> item in the destination widget with values taken from the selected item in
> the source widget. Both widgets have different custom type QTreeWidgetItems.
>
> I have implemented this from the MouseMoveEvent with a
> QDrag::exec(Qt::CopyAction) and a simple text payload to test it out. In
> the receiver end I have overridden dragEnterEvent and dropEvent like so:
>
> void DragDropWidget::dragEnterEvent(QDragEnterEvent *event)
>
> {
>
> qDebug() << "dragEnter";
>
> if (event->mimeData()->hasFormat("text/plain"))
>
> event->acceptProposedAction();
>
> }
>
>
> void DragDropWidget::dropEvent(QDropEvent *event)
>
> {
>
> qDebug() << "drop: " << event->mimeData()->text();
>
> event->acceptProposedAction();
>
>
> }
>
>
> Now, this works, but only if I set the receiving QTreeWidget dragDropMode
> to "InternalMove". I am worried that I'm doing this completely wrong, and
> that it just works accidentally when I set this flag... Any input?
>
> Cheers,
> Thomas
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160206/ac41e91b/attachment.html>
More information about the Interest
mailing list