Floating sub QMainWindow (QMainWindow as child widget of main QMainWindow)

痞子三分冷 提交于 2019-12-13 16:25:59

问题


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.

  1. https://qt-project.org/forums/viewthread/17519
  2. 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);
}

Related: a , b


回答1:


The Qt::Desktop flag is not something you are supposed to set by yourself.

You need to set the Qt::Window flag:

setWindowFlags(m_infoAreaFloating ? Qt::Window : Qt::Widget);
show();

There's no point to this->windowFlags() & ~Qt::Window: you've cleared all other window flags when setting the lone Qt::Window flag. You're in full control of the flags, there's no need to preserve some "other" flags: there are none.



来源:https://stackoverflow.com/questions/24917115/floating-sub-qmainwindow-qmainwindow-as-child-widget-of-main-qmainwindow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!