PDA

View Full Version : rearrange windows in a QMdiArea



ich
24th April 2015, 12:54
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´.

ChrisW67
27th April 2015, 09:24
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);