[Interest] Drag & Drop between QTreeWidgets

Thomas Sevaldrud thomas at silentwings.no
Sat Feb 6 13:35:37 CET 2016


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/5fdc8119/attachment.html>


More information about the Interest mailing list