PDA

View Full Version : How can I drag a file out of a TreeView and into another application?



donnaroma
18th June 2021, 03:04
I have a Treeview with QStandardItems. Each item has a path url to a local audio file and I am not sure how to add the ability to drag on of those items into another app like VLC.

I am subclassing the TreeView class and overriding these methods

//Mouse press event, start drag event
void mousePressEvent(QMouseEvent* event) override;

// //drag operation in the form move event
void dragMoveEvent(QDragMoveEvent* event) override;

// //drag operation enters the form
void dragEnterEvent(QDragEnterEvent* event) override;
void dragLeaveEvent(QDragLeaveEvent* event) override;

// //drop release event
void dropEvent(QDropEvent* event) override;

Still whenever I drag out an Item is is disabled

Ginsengelf
18th June 2021, 07:00
Hi, please show us how you create your QDrag object.

Ginsengelf

d_stranz
18th June 2021, 15:38
Still whenever I drag out an Item is is disabled

If you do not create your QDrag object with QMimeData of the correct MIME type for VLC (or whatever the other app expects), then the other app will not accept it. So as Ginsengelf says:


please show us how you create your QDrag object.