Copying file(s) with drag and drop from Qt

2019-07-04 16:42发布

问题:

How do I go about generating a file drag and drop operation in a Qt 5.2 application that performs a copy (or move) in the file system (Windows, Mac, etc.)? More specifically: Generate a drag with 1+ file paths that will perform a copy/move on those files when dropped onto the system.

Is there a standard mime-type I can use for this - providing file paths as mime data?

回答1:

QMimeData has a functionality to add a text/uri-list.

To drag/drop a file onto the system add a QUrl that starts with file:/// followed by your path.

QList<QUrl> urls;

list.append(QUrl("file:///path");

QMimeData* mimeData = new QMimeData;

mimeData->setUrls(list);