chezifresh
21st March 2011, 21:52
I have a list widget that contains file paths. I want to be able to drag and drop the list widget items to external applications.
For instance, I would drag an item to the desktop and it would copy the file to the desktop. If I drag it to thunderbird's text area it would paste in the path to the file.
Here's what I have:
QMimeData * ListWidget::mimeData(const QList<QListWidgetItem *> items) {
QList<QUrl> urls;
urls.append("file:///foo/bar/baz.txt");
urls.append("file:///foo/bar/xyx.txt");
QString text;
text = "file:///foo/bar/baz.txt file:///foo/bar/xyx.txt";
QMimeData * data = new QMimeData();
data->setText(text);
data->setUrls(urls);
return data;
}
The weird thing is, when I drag the item onto thunderbird, it interleaves the two, so I'll get something like this:
'file:///foo/bar/baz.txt' 'file:///foo/bar/xyx.txt''file:///foo/bar/baz.txt 'file:///foo/bar/xyx.txt'
Calling just setUrls, thunderbird wont even accept the drop event over the text area, just as an attachment. I'm wondering if I'm just doing this the wrong way, or if this is a bug in thunderbird, as well as other applications. Similar things happen dragging to the Gnome Terminal.
For instance, I would drag an item to the desktop and it would copy the file to the desktop. If I drag it to thunderbird's text area it would paste in the path to the file.
Here's what I have:
QMimeData * ListWidget::mimeData(const QList<QListWidgetItem *> items) {
QList<QUrl> urls;
urls.append("file:///foo/bar/baz.txt");
urls.append("file:///foo/bar/xyx.txt");
QString text;
text = "file:///foo/bar/baz.txt file:///foo/bar/xyx.txt";
QMimeData * data = new QMimeData();
data->setText(text);
data->setUrls(urls);
return data;
}
The weird thing is, when I drag the item onto thunderbird, it interleaves the two, so I'll get something like this:
'file:///foo/bar/baz.txt' 'file:///foo/bar/xyx.txt''file:///foo/bar/baz.txt 'file:///foo/bar/xyx.txt'
Calling just setUrls, thunderbird wont even accept the drop event over the text area, just as an attachment. I'm wondering if I'm just doing this the wrong way, or if this is a bug in thunderbird, as well as other applications. Similar things happen dragging to the Gnome Terminal.