浮动的子QMainWindow(将QMainWindow作为主QMainWindow的子窗口)

3
我在主QMainWindow中使用一个QMainWindow作为子窗口,从而获得另一个可用于可停靠小部件(QDockWidget)的区域。根据以下帖子,这是可以的,并且对我来说也完美地运作。
  1. https://qt-project.org/forums/viewthread/17519
  2. http://www.qtcentre.org/threads/12569-QMainWindow-as-a-child-of-QMainWindow
QMainWindow 作为普通小部件进行设置,我取消了窗口标志,这个技巧在上面的帖子中提到过。
现在我还想能够浮动此子 QMainWindow 和其所有停靠小部件。换句话说,我想撤销“将其设置为普通小部件”的步骤。不幸的是,这并不起作用。它已经从主窗口中消失,但根本看不见。
有什么解决办法吗?
// 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);
}

相关链接:ab
1个回答

4
< p > Qt::Desktop 标记不是您自己设置的内容。

您需要设置Qt::Window标记:

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

this->windowFlags() & ~Qt::Window 没有意义:当设置独立的 Qt::Window 标志时,您已清除了所有其他窗口标志。您可以完全控制标志,没有必要保留一些“其他”标志:根本没有其他标志。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接