QDockWidget - 浮动时没有边框的窗口 [英] QDockWidget - window with no borders when floating

查看:3793
本文介绍了QDockWidget - 浮动时没有边框的窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Win 7,Qt 5.3

Win 7, Qt 5.3

我使用一个 QDockWidget

现在,通过将 setTitleBarWidget(new QWidget(this))设置为默认构造的小部件。这是根据Qt文档的标准方法。

Now I hide the title bar by setting setTitleBarWidget(new QWidget(this)) to a default constructed widget. This is the standard way according to Qt documentation. Also works, title bar is gone.

为了取消我的窗口部件作为窗口,我使用 myDockWidget-> setFloating(true) code>(在我自己的插槽)。但现在,当窗口部件被取消停靠,浮动窗口不再有边框(因此不能移动)。

In order to undock my widget as window, I use myDockWidget->setFloating(true) (in my own slot). But now, when the widget is undocked, the floating window has no longer borders (hence cannot be moved).

如果我注释掉 setTitleBarWidget ,还要 myDockWidget-> setFloating(true) / code>工程。所以原来的标题栏似乎包含了一些逻辑。但是,通过查看源代码我找不到任何特别的。

If I comment out setTitleBarWidget , also myDockWidget->setFloating(true) works. So the original title bar seems to incorporate some logic. However, by looking at the source code I could not find anything special.

任何提示我可以做些什么来克服这个问题?

Any hint what I can do to overcome the issue?

推荐答案

这是预期的行为。请参阅 QDockWidget :: setTitleBarWidget docs:

This is the expected behavior. See QDockWidget::setTitleBarWidget docs:


如果设置了标题栏小部件,

If a title bar widget is set, QDockWidget will not use native window decorations when it is floated.

此行为的目的是允许为dock实现完全自定义的标题栏

The purpose of this behavior is to allow implementing fully customized title bar for dock widget.

一个解决方法是连接到小部件变为浮动时发出的 QDockWidget :: topLevelChanged 信号停靠,并将标题栏小部件设置为0,只要它是浮动的,以恢复默认行为。

A workaround is to connect to QDockWidget::topLevelChanged signal that is emitted when the widget becomes floating or docked, and set title bar widget to 0 as long as it's floating to restore default behavior.

请注意,在设置默认设置时,上一个标题栏小部件不会被删除,因此您应该删除以前使用的QWidget或保存指针并在下次使用。

Note that previous title bar widget is not deleted when default one is set, so you should either delete previously used QWidget or save a pointer to it and use it the next time.

这篇关于QDockWidget - 浮动时没有边框的窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆