Panel (hide/show)
-
Is there a component/widget to a panel with a button to hide and show?
Example:
-
Hello again.
I think you can achive desired behaviour by using "QDockWidget":http://qt-project.org/doc/qt-4.8/QDockWidget.html#details.
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":http://qt-project.org/doc/qt-4.8/qdockwidget.html#toggleViewAction method of dockwidget to you toolbar.
That is it.
Screenshot:
!http://habrastorage.org/storage2/5f7/c23/b6a/5f7c23b6ae29fc71e99c98387b2b8751.png(dock_widget_example)!Code snippet:
@
QAction *action = findChild<QDockWidget *>()->toggleViewAction();
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. -
Thank you very much.
I do not want my QDockWidget floating. How i remove it?
-
First, more complicated example (sorry for bad code):
@
void MainWindow::control_dock(bool flag) {
if (flag) {
QDockWidget *dock = new QDockWidget (this);
dock->setWidget (new QWidget());
dock->setObjectName ("dock");
addDockWidget (Qt::RightDockWidgetArea, dock,Qt::Vertical);QAction *action = dock->toggleViewAction(); action ->setText ("Dock"); findChild<QToolBar *>()->addAction(action);
}
else {
QDockWidget *dock = findChild<QDockWidget *>("dock");
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:
!http://habrastorage.org/storage2/2f9/1df/e43/2f91dfe43478ed306775328a7165d509.png(menu_control_dock)!
(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":http://qt-project.org/doc/qt-4.8/qdockwidget.html#floating-prop method of it.
-
Thank you very much.
Is there a way to make a sidebar like the Qt Creator?
-
I'm sorry, but I don't know. Bt you may look in sources of Qt Creator for the answer.
-
It has a lot of code and I can not find.