PDA

View Full Version : Weird behavior when readding a window to a QMdiArea



seand
27th August 2008, 02:14
Hi,

I've searched around for a possible explanation for this, and taken a look in the source code, and I can't seem to find out why it's happening. I can explain this best with a series of pictures:

1) Regular MDI area, with two subwindows (both maximized):

http://img520.imageshack.us/img520/6650/img1kx1.th.png (http://img520.imageshack.us/my.php?image=img1kx1.png)

2) Moving one of the windows to the desktop (using removeSubWindow()). Also note the title of the main application:

http://img241.imageshack.us/img241/7214/img2dq2.th.png (http://img241.imageshack.us/my.php?image=img2dq2.png)

3) Moving the desktop QWidget back into the MDI area (using addSubWindow(), but now the main application title is messed up:

http://img84.imageshack.us/img84/8595/img3it1.th.png (http://img84.imageshack.us/my.php?image=img3it1.png)

There is other weird behavior, such as the fact that even though I use setFocus() to bring the subwindows to the front of the QMdiArea, when I get to step 3, the window isn't brought to the front, although the focus is still there (I can type in the active window's text box). I've found that I can make it revert to the default behavior if I have a 3rd window inside the QMdiArea and I bring the focus to that one (at which point the title of the main application goes back to normal, as does all the other behavior inside the QMdiArea). To bring the focus to a window, I use setFocus() and GiveFocus(). Here is the code I use for reparenting one of the windows:


// IWindow derives from QWidget
// WindowContainer derives from QMdiArea
// m_pContainer is of type WindowContainer
// m_pSubWindow is of type QMdiSubWindow
void IWindow::Reparent(WindowContainer *pContainer)
{
if(m_pContainer)
{
// if there's a valid container, there's a valid QMdiSubWindow
m_pContainer->removeSubWindow(m_pSubWindow);
m_pSubWindow->setWidget(NULL);
m_pSubWindow->close();
}

if(pContainer)
{
// we check to see if the active sub window is maximized, because if it is,
// we want the window being added to also be maximized automatically
bool max = pContainer->currentSubWindow() && pContainer->currentSubWindow()->isMaximized();
m_pSubWindow = pContainer->addSubWindow(this);
if(max)
{
m_pSubWindow->showMaximized();
}
pContainer->update();
}
// we're moving it to the desktop
else
{
// relocate it
move(m_pContainer->pos() + pos());
}

m_pContainer = pContainer;
show();
}


Thanks,
Sean