PDA

View Full Version : Drag & Drop in MDI application



Koas
31st August 2010, 10:25
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:


void mainWND::dragEnterEvent(QDragEnterEvent* event)
{
qDebug()<<"mainWND::dragEnterEvent";
//if (event->mimeData()->hasFormat("text/uri-list"))
event->acceptProposedAction();
}

void mainWND::dropEvent(QDropEvent* event)
{
qDebug()<<"mainWND::dropEvent";
//this->slProcessFileDrop(event->mimeData()->data("text/uri-list"));
event->acceptProposedAction();
}

void mainWND::dragMoveEvent(QDragMoveEvent* event)
{
qDebug()<<"mainWND::dragMoveEvent";
event->accept();
}
(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! :)

Koas
2nd September 2010, 10:05
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.

lsbts1291
2nd September 2011, 09:25
Try setting acceptDrops of the mainWND's centraWidget to false.


mainWND::mainWND()
{
//...
setAcceptDrops( true)
centralWidget->setAcceptDrops( false);
}