QMdiArea: Closing subwindows causes wrong subwindow to become current
I've got a problem that is driving me crazy. I'm sure it just me doing something stupid...
I have a QMainWindow that has a QMdiArea as its central widget. The subwindows in the QMdiArea contain datatables that are used to "drill down". After the following sequence of events:
QMdiArea *pMdiArea ....
CustomWidget1* cw1 = new CustomWidget1(pMdiArea);
CustomWidget2* cw2 = new CustomWidget2(cw1);
CustomWidget3* cw3 = new CustomWidget3(cw2);
The application now has 3 subwindows open, cw1 on bottom, cw2 in the middle, and cw3 on top. When I close cw3 (clicking on the window close button), cw1 pops up on top instead of cw2. I expect cw2 to pop up on top since it was a signal from this window that opened cw3 and it was the window on top before cw3 was opened.
I have tried creating the subwindows with the mainwindow as their parent, as well as the mdi area in the hopes that that would have some effect, but to no avail.
Is there some setting or just something stupid that I am doing here? I can't for the life of me find anything relevant in the documentation and my google-fu is failing me. It is REALLY annoying in the application to have the wrong subwindow gain focus. I know I could put in a signal/slot setup to force the correct order but that seems like it should be unnecessary.
Any help would be greatly appreciated.
[EDIT: code formatting, please use @-tags, Volker]
Ok, so I'm stupid. Just needed
why do you create cw2 as child of cw1? Then you reparent it to the the mdi area while calling pMdiArea->addSubWindow(cw2); ?
That was just an attempt to get the mdiarea to recognize the order of precedence (I was hoping for undocumented magic). I originally constructed them with the mainwindow as the parent, though I suspect it really doesn't make a bit of difference since they are going to be reparented regardless. What had me stuck was the documentation for "setActivationOrder", which despite it obvious name, only states that it affects the ordering of the results of subwindowList(). I honestly didn't expect QMdiArea to reorder the current window layouts simply because one of the windows was closed, I would have expected it just to remove the closed window from the current display order.
Live and learn I suppose.