drag and drop: drag item from QListWidget to desktop or any open directory
Hi everyone!
I have QListWidget who contains list of files path. This files i'm dropped from explorer,
but i don't know how to implement drag and drop from QListWidget to the desktop or explorer.
This is my try...
Code:
void FileListWidget::startDrag()
{
if (currentItem()) {
QFile src
(currentItem
()->text
());
data = src.readAll();
src.close();
mime->setData("text/uri-list", data);
drag->setMimeData(mime);
drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction);
}
}
... but it's not working (error when copying file). Please explain me, what should I do to solve this problem?
P.S. Sorry for my bad English:o
Re: drag and drop: drag item from QListWidget to desktop or any open directory
Ah, only a minor misunderstanding.
You don't have to read the file and send its contents, you just send its filename.
Something like this
Code:
QFIleInfo fileInfo(currentItem()->text());
QUrl url
= QUrl::fromLocalFile(fileInfo.
absoluteFilePath());
mime->setUrls(QList<QUrl>() << url);
...
Cheers,
_
Re: drag and drop: drag item from QListWidget to desktop or any open directory
Thank you very much for help... it's work! :)