February 27, 2011

Outtascope Outtascope
Lab Rat
4 posts

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:

  1. QMdiArea *pMdiArea ....
  2.  
  3. CustomWidget1* cw1 = new CustomWidget1(pMdiArea);
  4. pMdiArea->addSubWindow(cw1);
  5. CustomWidget2* cw2 = new CustomWidget2(cw1);
  6. pMdiArea->addSubWindow(cw2);
  7. CustomWidget3* cw3 = new CustomWidget3(cw2);
  8. pMdiArea->addSubWindow(cw3);

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]

3 replies

February 27, 2011

Outtascope Outtascope
Lab Rat
4 posts

Ok, so I’m stupid. Just needed

  1. pMdiArea->setActivationOrder(QMdiArea::ActivationHistoryOrder);

February 28, 2011

Gerolf Gerolf
Area 51 Engineer
3210 posts

Hi Outtascope,

why do you create cw2 as child of cw1? Then you reparent it to the the mdi area while calling pMdiArea->addSubWindow(cw2); ?

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

February 28, 2011

Outtascope Outtascope
Lab Rat
4 posts

Gerolf, 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.

 
  ‹‹ Many PushButton      [SOLVED]QSqlTableModel and QTableView ››

You must log in to post a reply. Not a member yet? Register here!