Is there a component/widget to a panel with a button to hide and show?
I think you can achive desired behaviour by using QDockWidget [qt-project.org].
- 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.
- action ->setText ("Dock");
- findChild<QToolBar *>()->addAction(action);
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):
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.
(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.