Solved Drag and drop between different QMdiSubwindows
-
Hey Qt Devs
I need a hint how to raise an inactive QMdiSubwindow when I put mouse over it, while I have pending drag operation initiated from other subwindow. So far as I tested
dragEnterEvent()
,enterEvent()
and so on don't work due to other window is inactive. What else I can use to detect drag went over another subwindow? -
I managed to solve this on my own. I share the solution in case of someone will also occur such issue.
ReimplementingdragEnterEvent()
is necessary, and here is how:void AComplexWidgetPutIntoMdiSubwindowWhoseChildStartsDragNDrop::dragEnterEvent(QDragEnterEvent *event) { if (event->mimeData()->hasFormat(supportedMimeFormat))//supported mime is something you define { QMdiSubWindow *w = qobject_cast<QMdiSubWindow*>(parent());//this gets QMdiSubwindow for the widget QMdiArea *area = w->mdiArea(); area->setActiveSubWindow(w);//and this causes it to be raised as top, active window } QWidget::dragEnterEvent(event); }
-
I managed to solve this on my own. I share the solution in case of someone will also occur such issue.
ReimplementingdragEnterEvent()
is necessary, and here is how:void AComplexWidgetPutIntoMdiSubwindowWhoseChildStartsDragNDrop::dragEnterEvent(QDragEnterEvent *event) { if (event->mimeData()->hasFormat(supportedMimeFormat))//supported mime is something you define { QMdiSubWindow *w = qobject_cast<QMdiSubWindow*>(parent());//this gets QMdiSubwindow for the widget QMdiArea *area = w->mdiArea(); area->setActiveSubWindow(w);//and this causes it to be raised as top, active window } QWidget::dragEnterEvent(event); }