Results 1 to 3 of 3

Thread: drag and drop: drag item from QListWidget to desktop or any open directory

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2014
    Posts
    2
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default drag and drop: drag item from QListWidget to desktop or any open directory

    Hi everyone!
    I have QListWidget who contains list of files path. This files i'm dropped from explorer,
    but i don't know how to implement drag and drop from QListWidget to the desktop or explorer.
    This is my try...
    Qt Code:
    1. void FileListWidget::startDrag()
    2. {
    3. if (currentItem()) {
    4. QByteArray data;
    5. QFile src(currentItem()->text());
    6. src.open(QIODevice::ReadOnly);
    7. data = src.readAll();
    8. src.close();
    9. QMimeData *mime = new QMimeData;
    10. mime->setData("text/uri-list", data);
    11.  
    12. QDrag *drag = new QDrag(this);
    13. drag->setMimeData(mime);
    14. drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction);
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 
    ... but it's not working (error when copying file). Please explain me, what should I do to solve this problem?

    P.S. Sorry for my bad English
    Last edited by Vovasty; 29th January 2014 at 14:55.

Similar Threads

  1. to use drag & drop on QListWidget
    By giorgik in forum Qt Programming
    Replies: 1
    Last Post: 19th October 2012, 18:00
  2. Drag and drop between QListWidget's
    By estanisgeyer in forum Qt Programming
    Replies: 4
    Last Post: 17th February 2011, 04:29
  3. Replies: 3
    Last Post: 10th June 2010, 15:13
  4. Replies: 1
    Last Post: 22nd October 2009, 00:02
  5. QListWidget Drag and Drop problem
    By winkle99 in forum Qt Programming
    Replies: 0
    Last Post: 20th October 2009, 20:00

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.