View Full Version : QDockWidget

26th April 2006, 22:35
QDockWidgets have a lot of cool things that they do! However, I need them to do more. I've searched but haven't found anything about hiding and showing or adding things to my titlebar.

Okay so first the hide/show.....
Right now I save the state of my mainwindow and then restore it. But this isn't the ideal way of doing things. Because I want to hide and show different dock widgets. I've tried to remove the widget and then add it later but that seems to mess QT up.
Any ideas on how to do this right? I will even take a pointer to documentation on this!

Can you add icons to the title bar? they have the redoc icon and the close icon but I would like to add an icon that max's the window out!

Thanks QT gurus!

26th April 2006, 22:45
DockWidgets have a method called:


What I did was create a slot that called the setHidden method from a button's signal.
This will toggle the dock window on and off.

26th April 2006, 22:53
I beleive that you can set the QStyle of the DockWidget with some key enums like the following:


26th April 2006, 23:55
Well, this all sounds great and what I want. While the hide/show for the dock worked great I am having some trouble with the max button. I see how it works I am trying to get it implemented to the dock widget. If I can get something I will post it. Until then thanks gurus for the replies!

27th April 2006, 16:56
Since I found this problem interesting and I pay for support. I decided to ask Trolltech about this issue.

They claim that there is no way to get a minimize or maxmize button in the title bar of a DockWidget.

I'm sure you can simulate these actions with some QButtons, but title bar buttons are a no go ... for the current release anyway.

29th April 2006, 00:24
I guess I got someone's attention at Trolltech on this issue for they sent me yet another email today. Here is the email I received:

The problem with this is that the floating dock widget is a
Tool window and Tool windows do not have minimize and maximize icons
since that is not their nature. What you should do is call
setWindowFlags() on the QDockWidget and specify that it should be a
window type and not a tool type and this will then give it the
appropriate titlebar. However this is not recommended as you could
have problems with the QDockWidget functionality, you should instead
put the widget in the QDockWidget into another widget that is top
level. Then you won't have problems with the docking behaviour of the

2nd May 2006, 19:01
So they want a widget that is a dockwidget that is my widget just to get a maximize button?

Or are they saying that when they expand the dockwidget I grab it and remove the widget from the dockwidget and put it into a new widget? - NAH that won't work because then how will it now it can dock to the main window again.

So does having a dockwidget within a widget go to the parent widget and give it docking capabilities?

hmmmm? :eek:

3rd May 2006, 20:44
you should instead
put the widget in the QDockWidget into another widget that is top
level. Then you won't have problems with the docking behaviour of the
He?! I don't get this. :confused:

I also tried add some buttons to a QDockWidget titlebar and if I remember right I managed to fake it :D
Create a button (or any other widget) in the dock widget and use negative coordinates to move it to the titlebar. This is an ugly hack but it worked for me.
IMHO the whole dock widget stuff is somehow closed up. It's nice if you use it like it is. But if you try to customize it...

26th June 2008, 19:52
I followed the advice of using setWindowFlags() and it worked for me. I did not notice any incorrect behavior from the dockWidget. Looks like the trolltech people have fixed it. Thanks!

// connect dockWidget's topLevelChanged signal, which is emitted when its floating property changes, to a user-defined slot
connect(ui.dockWidget, SIGNAL(topLevelChanged(bool)), this, SLOT(dockWidget_topLevelChanged(bool)));

// when the floating property of dockWidget is changed from docked to floating
// we make it a top level window (with minmize, maximize, and close button in the title bar)
// by calling setWindowFlags(Qt::Window)
// The dockWidget will automatically regain it's Qt::widget flag when it becomes docked again (by dragging it to the right place or double clicking the title bar)
void CMainWindow::dockWidget_topLevelChanged(bool isFloating)
{ ui.dockWidget->setWindowFlags(Qt::Window);
// setWindowFlags calls setParent() when changing the flags for a window, causing the widget to be hidden.
// You must call show() to make the widget visible again