PDA

View Full Version : Restore MDI Children w/correct window z-order



C403
22nd June 2013, 09:11
Hey,


Scratch the original post, my bad. Case in point, I have an MDI area with several sub windows I subclass directly from QMdiSubWindow. I need to save their z order when I close the session so I can restore it. I can already restore their geometry with save/restoreGeometry, thats not an issue. Children are given focus as they are activated, so I would have to dynamically activate them (as I did in MFC and it was a complete mess, but it worked).

Is there a better/cleaner way of doing it?

C403
22nd June 2013, 21:00
I solved it, in case anyone is interested this is what I did:

I override the main window (where the mdiArea object is) closeEvent, and there I get a list of all subwindows in StackOrder. I save each window's object name into the settings with the respective stack index. When I read them I use a QMap<QMdiSubWindow*, int> and a QStringList of settings.childKeys().

Code wise: (Adjust it to your needs):

In writeSettings in closeEvent:



QList<QMdiSubWindow*> subWindows = ui->mdiArea->subWindowList(QMdiArea::StackingOrder);

for(int i=0; i<subWindows.size(); i++)
{
settings.setValue(subWindows[i]->objectName(), i);
}



In readSettings:



QStringList keys = settings.childKeys();
QMap<int, QMdiSubWindow*> subWindowMap;

for(int i=0; i<keys.size(); i++)
subWindowMap.insert(settings.value(keys[i], 0).toInt(), ui->mdiArea->findChild<QMdiSubWindow*>(keys[i]));


for(int i=0; i<subWindowMap.size(); i++)
{
ui->mdiArea->setActiveSubWindow(subWindowMap.value(i));
}

This works fine, and is clean as far as I'm concerned.