Results 1 to 3 of 3

Thread: Drag & Drop in MDI application

  1. #1
    Join Date
    Sep 2008
    Posts
    13
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Drag & Drop in MDI application

    Hi all, I'm having some trouble implementing drag & drop in a MDI app. My app is a QMainWindow widget which has a QMdiArea as the central widget.

    In this QMdiArea I create one QMdiSubWindow and assign a custom QWidget to it using QMdiSubWindow->setWidget().

    The problem is that I don't receive any dragEnter or drop events in any of all these widgets. Here's what I've done in the code for the QMainWindow, QMdiArea, QMdiSubWindow and the custom QWidget:

    1.- Set the acceptDrops flag using setAcceptDrops(true);
    2.- Implemented the dragEnterEvent, dropEvent and dragMoveEvent:

    Qt Code:
    1. void mainWND::dragEnterEvent(QDragEnterEvent* event)
    2. {
    3. qDebug()<<"mainWND::dragEnterEvent";
    4. //if (event->mimeData()->hasFormat("text/uri-list"))
    5. event->acceptProposedAction();
    6. }
    7.  
    8. void mainWND::dropEvent(QDropEvent* event)
    9. {
    10. qDebug()<<"mainWND::dropEvent";
    11. //this->slProcessFileDrop(event->mimeData()->data("text/uri-list"));
    12. event->acceptProposedAction();
    13. }
    14.  
    15. void mainWND::dragMoveEvent(QDragMoveEvent* event)
    16. {
    17. qDebug()<<"mainWND::dragMoveEvent";
    18. event->accept();
    19. }
    To copy to clipboard, switch view to plain text mode 
    (code shown here is from the QMainWindow widget, but I have the same code in all the other widgets).

    As I said, I don't receive any events, not a single qDebug() statement is executed.

    Could anyone throw some light in here? Am I missing anything? I've read all the documentation about QMdiArea and QMdiSubWindow but it says nothing about the drag & drop.

    Thanks a lot!

  2. #2
    Join Date
    Sep 2008
    Posts
    13
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Drag & Drop in MDI application

    I've also tried installing an event filter in the widgets, and I'm shocked by the fact that the QMainWindow widget does not receive any events, but the QMdiArea does, a lot of mouse events but no drag or drop event.

  3. #3
    Join Date
    Sep 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Drag & Drop in MDI application

    Try setting acceptDrops of the mainWND's centraWidget to false.
    Qt Code:
    1. mainWND::mainWND()
    2. {
    3. //...
    4. setAcceptDrops( true)
    5. centralWidget->setAcceptDrops( false);
    6. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 3
    Last Post: 10th June 2010, 15:13
  2. Replies: 0
    Last Post: 4th May 2010, 10:24
  3. drag and drop from outside qt application
    By elflord in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2009, 15:40
  4. Replies: 4
    Last Post: 17th June 2007, 10:30
  5. Drag and drop outside the application
    By jpn in forum Newbie
    Replies: 7
    Last Post: 27th August 2006, 15:37

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.