Results 1 to 2 of 2

Thread: drag and drop from outside qt application

  1. #1
    Join Date
    Feb 2009
    Location
    Clermont-Ferrand, France
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default drag and drop from outside qt application

    Hello all:

    I would like to drag an image on my file system and drop to my qt application
    i've read the Qt documents and it seems the drag and drop function works within the same application window

    so my question is : is it the same way to program drag and drop in the two situations ?

    thanks

  2. #2
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: drag and drop from outside qt application

    Yes, in principle. The most portable way is to see if the mime data contains URLs.
    For example:
    Qt Code:
    1. class Widget : public QWidget
    2. {
    3. public:
    4. Widget()
    5. {
    6. setAcceptDrops(true);
    7. }
    8. void dragEnterEvent(QDragEnterEvent *event)
    9. {
    10. foreach(QUrl url, event->mimeData()->urls())
    11. if (QFileInfo(url.toLocalFile()).suffix().toUpper()=="PNG")
    12. {
    13. event->acceptProposedAction();
    14. return;
    15. }
    16. }
    17. void dropEvent(QDropEvent *event)
    18. {
    19. foreach(QUrl url, event->mimeData()->urls())
    20. {
    21. QString filename = url.toLocalFile();
    22. QString suffix = QFileInfo(filename).suffix().toUpper();
    23. if(suffix=="PNG")
    24. {
    25. event->acceptProposedAction();
    26. // do something
    27. continue;
    28. }
    29. }
    30. }
    31. };
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to spud for this useful post:

    HeyYO (2nd February 2011)

Similar Threads

  1. drag and drop QToolButton in QToolBar
    By NBilal in forum Qt Programming
    Replies: 1
    Last Post: 28th December 2008, 20:11
  2. Change cursor & status during Drag & Drop
    By ronlongo in forum Qt Programming
    Replies: 0
    Last Post: 1st December 2008, 16:56
  3. Drag and Drop QTableWidget and QTableView
    By scorpion11 in forum Qt Programming
    Replies: 5
    Last Post: 8th April 2008, 09:33
  4. Drag and drop outside the application
    By jpn in forum Newbie
    Replies: 7
    Last Post: 27th August 2006, 15:37
  5. Drag and drop revisited
    By Big Duck in forum Newbie
    Replies: 2
    Last Post: 30th June 2006, 16:41

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.