PDA

View Full Version : How to show/hide a whole docking area?



agarny
13th February 2013, 10:48
Hi,

My application has a few widgets which are docked to the left docking area of my application. Now, there are times where I wish my central widget would get as much real estate as possible. So, in that context, I wish there I could hide all my docked widgets at once, effectively hiding the left docking area (and not hiding each docked widget individually). Ideally, there would be some kind of a button to the right of my left docking area which, when clicked, would either show/hide the whole left docking area. I have googled around a bit for this, but couldn't find anything useful, but I can't imagine this couldn't be done, so... anyone, any idea?

Cheers, Alan.

Santosh Reddy
13th February 2013, 10:57
It is possible to do so, but the QDockWidget does not support this out of box. You will need to have a custom QDockWidget with a special button mechanism to hide / unhide, expect the button itself. That will mean that the dock widget will never be completely hidded, at-lest the button part of it will be visible.

agarny
13th February 2013, 11:02
Thanks, but if I was to have a 'special' QDockWidget, then it means that I could potentially move it around within the docking area. Also, it could be 'grouped' with one or several of my other docked widgets, etc. So, I am not sure how this could work efficiently for me...

Santosh Reddy
13th February 2013, 11:09
If you don't want the QDockWidget to move around, then set QDockWidget::setFeatures(QDockWidget::NoDockWidget Features)

Also you could use QDockWidget::setTitleBarWidget(), to set the custom title bar which has the hide/show button.

agarny
13th February 2013, 11:18
Ah, I clearly didn't know about QDockWidget::setFeatures(QDockWidget::NoDockWidget Features) and together with QDockWidget::setTitleBarWidget(), I can see that working. Now, I wouldn't want that 'special' QDockWidget to be visible when no other docked widgets are, but I guess I could catch some signal to find out when there is only one QDockWidget object left (i.e. the 'special' one) and thus hide it?...

Santosh Reddy
13th February 2013, 11:32
One other option is that you could use QMainWindow functions

QMainWindow::saveState()
QMainWindow::removeDockWidget() // remove all
...// Now central widget uses all the space
QMainWindow::addDockWidget() // Add them back
QMainWindow::restoreState()

agarny
13th February 2013, 11:35
Hmm... not sure that I like that solution, sorry. I mean that I have some menu items that I use to show/hide some dockable widgets, so that I get the feeling that it would mess everything up. No, I just want to be able to show/hide the docking area, not its docked widgets.