问题描述
我使用 QMainWindow
作为我的主要 QMainWindow
的子。我得到一个其他区域,我可以用于可停靠的小部件( QDockWidget
)。
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
要使 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.
现在我也想要能够浮动这个孩子 QMainWindow
及其所有停靠的窗口小部件。换句话说,我想恢复步骤使其成为一个正常的小部件。不幸的是,这不工作。
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);
}
相关:,
推荐答案
Qt :: Desktop
标志不是你自己应该设置的标志。
The Qt::Desktop
flag is not something you are supposed to set by yourself.
你需要设置 Qt: :Window
flag:
You need to set the Qt::Window
flag:
setWindowFlags(m_infoAreaFloating ? Qt::Window : Qt::Widget);
show();
没有意义 this-> windowFlags()& 〜Qt :: Window
:当您设置孤立 Qt :: Window
标志时,您已清除所有其他窗口标志。你完全控制了旗帜,没有必要保留一些其他旗帜:没有。
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.
这篇关于浮动子QMainWindow(QMainWindow作为子窗口部件的主要QMainWindow)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!