One approach that might work. Delay the execution of the rearrangement code using a zero-length timer connected to a slot that does the arrangement. The program will not try to rearrange the sub windows until the event loop is next reached, by which time the window should be gone.
// Subclass QMdiSubWindow and override closeEvent()
void MyMdiSubWindow
::closeEvent(QCloseEvent * closeEvent
) { if (mdiArea()) {
QTimer::singleshot(0, mdiArea
(),
SLOT(cascadeSubWindows
()));
// or emit a custom signal from this subwindow that you connect using a timer (at creation time) to some other target object and slot that does the work
}
QMdiSubWindow::closeEvent(closeEvent);
}
// Use your QMdiSubWindow subclass when adding the child windows to the area
MyMdiSubWindow *sub = new MyMdiSubWindow(this);
sub->setWidget(contentWidget);
ui->mdiArea->addSubWindow(sub);
// Subclass QMdiSubWindow and override closeEvent()
void MyMdiSubWindow::closeEvent(QCloseEvent * closeEvent) {
if (mdiArea()) {
QTimer::singleshot(0, mdiArea(), SLOT(cascadeSubWindows()));
// or emit a custom signal from this subwindow that you connect using a timer (at creation time) to some other target object and slot that does the work
}
QMdiSubWindow::closeEvent(closeEvent);
}
// Use your QMdiSubWindow subclass when adding the child windows to the area
MyMdiSubWindow *sub = new MyMdiSubWindow(this);
sub->setWidget(contentWidget);
ui->mdiArea->addSubWindow(sub);
To copy to clipboard, switch view to plain text mode
Bookmarks