Panel (hide/show)
Is there a component/widget to a panel with a button to hide and show?
Example:

6 replies
Hello again.
I think you can achive desired behaviour by using QDockWidget [qt-project.org].
How to:
- Add a tool bar or another widget as container for buttons.
- Add a dockwidget, make it closable.
- Add an action, returned by toggleViewAction [qt-project.org] method of dockwidget to you toolbar.
That is it.
Screenshot:

Code snippet:
- action ->setText ("Dock");
I used Designer to create UI, but of course you are free to implement the same in any other way. If so, you won’t probably need to call findChild.
Also, if you want to repeat behaviour of IDE on your screen shot, you should also add some button that enables/disables you dockwidget in order to add or remove action, associated with it.
First, more complicated example (sorry for bad code):
- void MainWindow::control_dock(bool flag) {
- if (flag) {
- dock->setObjectName ("dock");
- action ->setText ("Dock");
- }
- else {
- delete dock;
- }
- }
Here control_dock(bool flag) is a public slot. I’ve created a checkable menu item, which enables/disables dockwidget, and connected it’s signal triggered to control_dock slot. That is it.
AFAIK you don’t have to worry about deleting of action – it’s performed automaticaly.
Screenshot:

(I’ve moved toolBar at the bottom to make you see the button on it while menu is shown)
To make QDockWidget not floating, use setFloating [qt-project.org] method of it.
You must log in to post a reply. Not a member yet? Register here!

