I have a QMdiArea with several QMdiSubWindows. While construction, the QMdiArea is initialized as TabbedView and DocumentMode, so it looks like a QTabWidget by default.
When user clicks the tab to switch the sub windows, I want to add a confirmation, and if the user chooses cancel, the active tab will not be changed.
My solution is to handle the signal "subWindowActivated", and calls "setActiveSubWindow" back to the original sub window if the confirmation fails.
The problem is, the setActiveSubWindow call didn't work as expected. The active window is switched back to the original one, but the sub windows are no longer maximized, but overlapped. And the original sub window appears behind the user clicked one. I can call setWindowState to maximize the sub window, and set focus to it, but the sub window is still behind the user clicked one.
I want to know if there is proper way to switch back to the original sub window after user clicked a new one.
Below are some code pieces
MyClass::MyClass()
{
m_pMdiArea = new QMdiArea;
m_pMdiArea->setViewMode(QMdiArea::TabbedView);
m_pMdiArea->setDocumentMode(true);
connect (m_pMdiArea, SIGNAL(subWindowActivated(QMdiSubWindow *)), this, SLOT(subWindowActivate(QMdiSubWindow *)));
}
void MyClass::subWindowActivate(QMdiSubWindow * window)
{
if (!window || window == m_pCurrentWindow)
{
return;
}
if (ConfirmationRejected)
{
m_pMdiArea->setActiveSubWindow(m_pCurrentWindow);
return;
}
m_pCurrentWindow = window;
}