Results 1 to 5 of 5

Thread: Drop items onto explorer.exe

  1. #1
    Join Date
    Apr 2008
    Posts
    6
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Drop items onto explorer.exe

    Dear all, I would love to hear from someone who has got dropping items from a view onto explorer. I wish to drag items out of my tree view and have them become files. (.txt)

    This article seems to provide useful details.
    http://www.codeproject.com/KB/shell/...rdragdrop.aspx


    I have looked into the way windows does this and from what I understand, i need to create a COleDataSource. Constructing the data to pass to the source is a bit involved but ok.. then call DoDragDrop on the DataSource and your home and dry.

    Qt seems to have or fake something that can recieve windows drops, but does anyone have experience of dropping stuff from qt? I.e. how would I write a qt app that can use a COleDataSource?

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Drop items onto explorer.exe

    I guess u will need to look at the formats of the mimedata for drag and drop.
    You need to see what mimedata explorer accepts / processes and then set ur mimedata for drag acccordingly.

  3. #3
    Join Date
    Apr 2008
    Posts
    6
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Drop items onto explorer.exe

    As far as I have understood windows doesn't accept mime data drops. So you have to do it the windows way. I am up for having a crack at creating the data. Where I would love some help is in using the required Microsoft classes in my QT app. I am guessing that I will need to download the windows sdk. But this is uncharted territory for me and I would love to hear from someone who has used, or linked to microsoft code in a QT app.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Drop items onto explorer.exe

    You just have to dump the contents to a temp file. Here's a dummy example:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. class Label : public QLabel
    4. {
    5. protected:
    6. void mouseMoveEvent(QMouseEvent* event)
    7. {
    8. if (file.open())
    9. {
    10. QUrl url = QUrl::fromLocalFile(file.fileName());
    11. file.write(text().toUtf8());
    12. file.close();
    13.  
    14. QDrag* drag = new QDrag(this);
    15. QMimeData* mimeData = new QMimeData;
    16. mimeData->setUrls(QList<QUrl>() << url);
    17. drag->setMimeData(mimeData);
    18. drag->exec(Qt::CopyAction);
    19. }
    20. }
    21. };
    22.  
    23. int main(int argc, char* argv[])
    24. {
    25. QApplication app(argc, argv);
    26. Label label;
    27. label.setText("foo bar");
    28. label.show();
    29. return app.exec();
    30. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  5. The following user says thank you to jpn for this useful post:

    coolboy123 (4th December 2008)

  6. #5
    Join Date
    Mar 2007
    Posts
    3
    Thanks
    2

    Default Re: Drop items onto explorer.exe

    Thanks, it's what I am longing for...

    Quote Originally Posted by jpn View Post
    You just have to dump the contents to a temp file. Here's a dummy example:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. class Label : public QLabel
    4. {
    5. protected:
    6. void mouseMoveEvent(QMouseEvent* event)
    7. {
    8. if (file.open())
    9. {
    10. QUrl url = QUrl::fromLocalFile(file.fileName());
    11. file.write(text().toUtf8());
    12. file.close();
    13.  
    14. QDrag* drag = new QDrag(this);
    15. QMimeData* mimeData = new QMimeData;
    16. mimeData->setUrls(QList<QUrl>() << url);
    17. drag->setMimeData(mimeData);
    18. drag->exec(Qt::CopyAction);
    19. }
    20. }
    21. };
    22.  
    23. int main(int argc, char* argv[])
    24. {
    25. QApplication app(argc, argv);
    26. Label label;
    27. label.setText("foo bar");
    28. label.show();
    29. return app.exec();
    30. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Drag and Drop in a QTreeWidget subclass
    By kishore in forum Qt Programming
    Replies: 2
    Last Post: 14th May 2008, 07:12
  2. Drag Drop between Different Views
    By aamer4yu in forum Qt Programming
    Replies: 13
    Last Post: 8th December 2006, 04:29
  3. Drag & drop items on the same QTreeView
    By wind in forum Qt Programming
    Replies: 2
    Last Post: 11th October 2006, 14:29
  4. Selective highlighting of Items
    By Kapil in forum Qt Programming
    Replies: 3
    Last Post: 26th May 2006, 12:20
  5. Drag and drop items in view to sort order
    By Big Duck in forum Qt Programming
    Replies: 1
    Last Post: 25th May 2006, 19:43

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
  •  
Qt is a trademark of The Qt Company.