问题
Win 7, Qt 5.3
I use a QDockWidget
with my application. Works as intended.
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.
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).
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?
回答1:
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.
The purpose of this behavior is to allow implementing fully customized title bar for dock widget.
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.
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.
来源:https://stackoverflow.com/questions/24745685/qdockwidget-window-with-no-borders-when-floating