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
{
urlList = data->urls(); // retrieve list of urls
foreach
(QUrl url, urlList
) // iterate over list {
cout<<s2.toStdString()<<endl;
}
}
return true;
}
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;
}
To copy to clipboard, switch view to plain text mode
If I drag from the external folder, I get something like
file:///home/quad/ImageFolder/2092.jpg
file:///home/quad/ImageFolder/2092.jpg
To copy to clipboard, switch view to plain text mode
If I drag from the qlistwidget, I get something like
2092
2092
To copy to clipboard, switch view to plain text mode
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)
{
myFilters << "*.jpg";
myFilters << "*.JPG";
myFilters << "*.png";
myFilters <<"*.PNG";
QDirIterator myIterator(node.path(),
myFilters,
);
QDirIterator myIterator2(node.path(),
myFilters,
);
while (myIterator2.hasNext())
{
QString myFileName
= myIterator2.
next();
if (!myFileInfo.isFile()) continue; //check the file exists
mypItem->setIcon(myPixmap);
mypItem->setData(Qt::UserRole,myFileName);
qlistwidget->addItem(mypItem);
}
qlistwidget->sortItems(Qt::AscendingOrder);
}
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);
}
To copy to clipboard, switch view to plain text mode
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
Bookmarks