Results 1 to 2 of 2

Thread: how to drag items from qlistwidget with the item's path info?

  1. #1
    Join Date
    Sep 2008
    Posts
    23
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Question how to drag items from qlistwidget with the item's path info?

    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
    Qt Code:
    1. bool MyTreeWgt::dropMimeData(QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action)
    2. {
    3. urlList = data->urls(); // retrieve list of urls
    4. foreach(QUrl url, urlList) // iterate over list
    5. {
    6. QString s2 = url.toString();
    7. cout<<s2.toStdString()<<endl;
    8. }
    9. }
    10. return true;
    11. }
    To copy to clipboard, switch view to plain text mode 
    If I drag from the external folder, I get something like
    Qt Code:
    1. 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
    Qt Code:
    1. 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
    Qt Code:
    1. void mainwindow::fillList(QDir& node)
    2. {
    3. QStringList myFilters;
    4. myFilters << "*.jpg";
    5. myFilters << "*.JPG";
    6. myFilters << "*.png";
    7. myFilters <<"*.PNG";
    8. QDirIterator myIterator(node.path(),
    9. myFilters,
    10. QDir::Files | QDir::AllDirs
    11. );
    12. QDirIterator myIterator2(node.path(),
    13. myFilters,
    14. QDir::Files | QDir::AllDirs
    15. );
    16. while (myIterator2.hasNext())
    17. {
    18. QString myFileName = myIterator2.next();
    19. QFileInfo myFileInfo(myFileName);
    20. if (!myFileInfo.isFile()) continue; //check the file exists
    21. QPixmap myPixmap(myFileName);
    22. QListWidgetItem * mypItem = new QListWidgetItem(myFileInfo.baseName());
    23. mypItem->setIcon(myPixmap);
    24. mypItem->setData(Qt::UserRole,myFileName);
    25. qlistwidget->addItem(mypItem);
    26. }
    27. qlistwidget->sortItems(Qt::AscendingOrder);
    28. }
    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
    Last edited by zl2k; 5th September 2008 at 20:53. Reason: updated contents

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to drag items from qlistwidget with the item's path info?

    You have to make QListWidget send the data you need.

Similar Threads

  1. qlistwidget count of selected items
    By tpf80 in forum Newbie
    Replies: 4
    Last Post: 10th December 2009, 13:31
  2. undo for multiple selected items
    By mooreaa in forum Qt Programming
    Replies: 3
    Last Post: 13th July 2008, 14:13
  3. Replies: 1
    Last Post: 5th June 2008, 14:02
  4. QListWidget help please
    By munna in forum Qt Programming
    Replies: 5
    Last Post: 28th November 2006, 12:16
  5. Get Visible Items from the QListWidget
    By srj in forum Qt Programming
    Replies: 4
    Last Post: 22nd November 2006, 20:13

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.