I use a QMainWindow
as child of my main QMainWindow
. By that I get an other area which I can use for dockable widgets (QDockWidget
).
According to the following posts this is OK, it also works perfectly for me.
- https://qt-project.org/forums/viewthread/17519
- http://www.qtcentre.org/threads/12569-QMainWindow-as-a-child-of-QMainWindow
To make the QMainWindow
behaving as a normal widget, I unset the window flag, this trick is mentioned in one of the posts above.
Now I also want to be able to float this child QMainWindow
with all its docked widgets. In other words, I want to revert the step "making it a normal widget". Unfortunately, this does does not work. It is gone from the main window, but not visible at all.
Any way to resolve it?
// this is the child QMainWindow
if (this->m_infoAreaFloating)
{
// this should give me a floating window besides the main window
this->setWindowFlags(Qt::Desktop);
this->show();
}
else
{
// make this compliant as QWidget
this->setWindowFlags(this->windowFlags() & ~Qt::Window);
}
The
Qt::Desktop
flag is not something you are supposed to set by yourself.You need to set the
Qt::Window
flag:There's no point to
this->windowFlags() & ~Qt::Window
: you've cleared all other window flags when setting the loneQt::Window
flag. You're in full control of the flags, there's no need to preserve some "other" flags: there are none.