rearrange windows in a QMdiArea
Hi, I want to rearrange the subwindows(QMainWindows) in the QMdiArea, after closing one of them. When I push the "closebutton" the subwindows sent an event to the MainWindow that includes the mdiArea and the Slot to this event rearrange the subwindow, the problem now is, that I get a gab between the rearranged subwindows because the program first rearrange the subwindows and secondly close the subwindow that is to close.
Is there any way I can implement that the subwindow sents the closing event to the main window, than close itself and after closing the other subwindow become rearranged ?
Thanks for any help !
Additionally: I use Qt 4.8.5 with still(caused by the historical growing of the program) some Qt3 elements. I work with Visual Studio´.
Re: rearrange windows in a QMdiArea
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.
Code:
// 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);