View Full Version : how to drag items from qlistwidget with the item's path info?

5th September 2008, 19:18
hi, there
I need to drag multiple selected qlistwidgetitem into another qtreewidget to pass the dirs into qtreewidget and I'll do my personal stuff using the dirs. I have read the examples on qt and http://sector.ynet.sk/qt4-tutorial/dnd.html.

The qlistwidget is contains thumbnail view of images in a folder ImageFolder. The qtreewidget can see the items passed into it, but the content of the items are different by dropping from the qlistwidget and by dropping form external window of ImageFolder.


bool MyTreeWgt::dropMimeData(QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action)
urlList = data->urls(); // retrieve list of urls
foreach(QUrl url, urlList) // iterate over list
QString s2 = url.toString();
return true;

If I drag from the external folder, I get something like


If I drag from the qlistwidget, I get something like

How can I get the path info for the images and also the .jpg?

Here is the piece of code when I populate the qlistwidget with thumbnails

void mainwindow::fillList(QDir& node)
QStringList myFilters;
myFilters << "*.jpg";
myFilters << "*.JPG";
myFilters << "*.png";
myFilters <<"*.PNG";
QDirIterator myIterator(node.path(),
QDir::Files | QDir::AllDirs
QDirIterator myIterator2(node.path(),
QDir::Files | QDir::AllDirs
while (myIterator2.hasNext())
QString myFileName = myIterator2.next();
QFileInfo myFileInfo(myFileName);
if (!myFileInfo.isFile()) continue; //check the file exists
QPixmap myPixmap(myFileName);
QListWidgetItem * mypItem = new QListWidgetItem(myFileInfo.baseName());

Basically, the thumbnail in the qlistwidget has name "2092". If I set the text to it's path as "file:///home/quad/ImageFolder/2092.jpg", then I can pass the dir info into the qtreewidget. But, I don't like such a long name under each thumbnail. So, how can I display the thumbnail neat and still can pass their dir into the qtreewidget as the external window did?

Thanks for your comments.


5th September 2008, 23:54
You have to make QListWidget send the data you need.