PDA

View Full Version : MdiSubWindows



DmitryNik
27th September 2011, 17:43
Hello!

I have a small problem with documentation understanding at this moment probably. In documentation we can find out, that mdisubwindow has a very good property IsActivated. And as I understand the active window is that window, which currently has a focus on itself. So, in this case how it's possible that two/three etc. sub-windows in MDIArea can be active simultaneously(when I try to close only the active one, all sub-windows shall be closed)? What the sub-window state depends on?

Thank you for your answers beforehand.

dennis81
27th September 2011, 18:20
Only one subwindow can be active.
QMdiSubWindow * QMdiArea::activeSubWindow () const
returns the active one.

I think if you close it, another subwindow gets the active state.
See QMdiArea::WindowOrder.

DmitryNik
27th September 2011, 20:27
Thank you for your answer. I'll try it.

p.s. I tried foreach loop for getting all sub-windows an dI used break key-word for braking the loop. So in this situation the non-active sub-window was closed firstly... I'm a bit confused.

ChrisW67
28th September 2011, 00:53
You don't need a loop to close the active sub-window, so I have no idea what 'foreach' or 'break' have to do with this. Post the code or we will remain as confused as you.

DmitryNik
28th September 2011, 06:58
Sorry, guys about that, my mistake. OK, here is the code:


foreach(QMdiSubWindow *sub, this->mdiWin->subWindowList())
{
if(sub->isActiveWindow())
{
sub->close();
break;
}
}


So in this case the window, which was opened first, will be closed, even it's not an active window. In this code "this" - is window, which central widget is MdiArea's object (mdiWin). In each sub-window we have a simple widget, let's say, PushButton.

ChrisW67
28th September 2011, 10:56
isActiveWindow() returns true for all the MDI sub-windows because their window(), which is the next ancestor widget that has (or could have) a window-system frame, is the same window and is active.

Try this:


QMdiSubWindow *sw = mdiWin->activeSubWindow();
if (sw)
sw->close();

DmitryNik
28th September 2011, 11:46
Thank you.
I didn't consider that at all. I thought, that each sub-window has its own flag. So it's mostly my misunderstanding.