PDA

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



zl2k
5th September 2008, 20: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.

In


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();
cout<<s2.toStdString()<<endl;
}
}
return true;
}

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


file:///home/quad/ImageFolder/2092.jpg

If I drag from the qlistwidget, I get something like

2092
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(),
myFilters,
QDir::Files | QDir::AllDirs
);
QDirIterator myIterator2(node.path(),
myFilters,
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());
mypItem->setIcon(myPixmap);
mypItem->setData(Qt::UserRole,myFileName);
qlistwidget->addItem(mypItem);
}
qlistwidget->sortItems(Qt::AscendingOrder);
}


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.

zl2k

jacek
6th September 2008, 00:54
You have to make QListWidget send the data you need.