[Qt-interest] QMainWindow stays below other windows on Windows
John Weeks
john at wavemetrics.com
Wed Sep 8 20:26:34 CEST 2010
I haven't had much success with getting answers here; maybe I ask
difficult questions or maybe I am too wordy. I'd be curious to know...
When I get answers they are generally excellent.
Anyway, I am developing an application with the ability to switch from
MDI mode to SDI mode, a la Qt Designer. One window is special and in
SDI mode it is parented with a QMainWindow; the special compound
widget is set as the central widget. Other (future document windows)
are just plain QWidgets with the Window flag set.
On Macintosh, this works fine.
On Windows, it almost works fine, but the special QMainWidget window
stays below the other windows even when it is the active window! I was
wondering if anyone might have some insight into this problem- ideas
of where to look for a solution.
I just noticed- on Windows, the whole application remains on top, even
when another application (Visual Studio or Windows Explorer) is
active! Is my problem some application setting?
I have pasted below the code that makes the switch, and creates the
QMainWindow for the special window.
Thanks in advance!
Regards,
John Weeks
WaveMetrics, Inc.
Phone (503) 620-3001
Fax (503) 620-6754
email support at WaveMetrics.com
void IgorAppObject::initializeMDIstyle(bool doMDI, bool force)
{
QList<windowInfo> WindowInfoList;
if (!force)
{
if (doMDI == isMDI)
return;
}
// IgorQtWindowGroup is a partial emulation of Macintosh window
groups. It is not involved in
// in the problem; the problem exists even when there are no groups
instantiated.
IgorQtWindowGroup::defilterForStateChange();
if (!_IgorWindowList.isEmpty()) // list of all the document
windows: these are derived
// from QWidget
{
// gather information on position, etc., to be restored after app
style switch
for (int i = 0; i < _IgorWindowList.size(); ++i)
{
windowInfo wi;
IgorWindow *w = _IgorWindowList[i];
wi.isVisible = w->isVisible();
wi.geometry = w->WMgetGeometry();
wi.f = w->windowFlags();
WindowInfoList.push_back(wi);
w->setParent(0);
}
}
// MDI mode is not a problem
if (doMDI)
{
MDIParent = new QMainWindow(NULL);
mdiArea = new QMdiArea(MDIParent);
MDIParent->setCentralWidget(mdiArea);
commandWindowDock = new QDockWidget(mdiArea);
MLCommandWindow * commandWindow = getMLCommandWindow();
QSize commandWindowSize = commandWindow->size();
commandWindowDock->resize(commandWindowSize);
commandWindow->setParent(commandWindowDock);
commandWindowDock->setWidget(getMLCommandWindow());
MDIParent->addDockWidget(Qt::BottomDockWidgetArea, commandWindowDock);
MDIParent->show();
#ifndef Q_WS_MAC
QMenuBar * mbar = IgorAppObject::getIgorMenuBar();
mbar->setParent(0);
MDIParent->setMenuBar(mbar);
mbar->show();
#endif
delete commandWindowMain;
commandWindowMain = NULL;
isMDI = true;
if (!_IgorWindowList.isEmpty())
{
for (int i = 0; i < _IgorWindowList.size(); ++i)
{
IgorWindow *w = _IgorWindowList[i];
Qt::WindowFlags f = WindowInfoList[i].f;
QMdiSubWindow *sw = mdiArea->addSubWindow(w, f);
w->WMSetGeometry(WindowInfoList[i].geometry);
sw->show();
}
}
}
else // SDI mode exhibits the problem
{
// MLCommandWindow is the special window
// make a QMainWindow for the MLCommandWindow to live in
commandWindowMain = new QMainWindow(NULL);
getMLCommandWindow()->setParent(commandWindowMain);
commandWindowMain->setCentralWidget(getMLCommandWindow());
commandWindowMain->show();
#ifndef Q_WS_MAC
QMenuBar * mbar = IgorAppObject::getIgorMenuBar();
mbar->setParent(0);
commandWindowMain->setMenuBar(mbar);
mbar->show();
#endif
QWidget *tempMDIParent = MDIParent;
// MDIParent is used as the parent widget for all document windows
when in SDI mode
MDIParent = commandWindowMain;
delete tempMDIParent;
isMDI = false;
// restore document window characteristics
if (!_IgorWindowList.isEmpty())
{
for (int i = 0; i < _IgorWindowList.size(); ++i)
{
IgorWindow *w = _IgorWindowList[i];
w->setParent(MDIParent);
Qt::WindowFlags f = WindowInfoList[i].f;
f |= Qt::Window;
w->setWindowFlags(f);
QRect r = WindowInfoList[i].geometry;
w->WMSetGeometry(r);
if (WindowInfoList[i].isVisible)
w->show();
}
}
}
IgorQtWindowGroup::refilterForStateChange();
// this is code that I added trying to solve my problem. It makes no
difference.
if (commandWindowMain)
{
Qt::WindowFlags f = commandWindowMain->windowFlags();
f |= (Qt::WindowStaysOnTopHint | Qt::CustomizeWindowHint);
commandWindowMain->setWindowFlags(f);
commandWindowMain->show();
commandWindowMain->activateWindow();
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100908/210acde3/attachment.html
More information about the Qt-interest-old
mailing list