Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Panel (hide/show)
Qt 6.11 is out! See what's new in the release blog

Panel (hide/show)

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 9.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Is there a component/widget to a panel with a button to hide and show?

    Example:

    !http://i.minus.com/ii99BufUo0M0Y.png!

    1 Reply Last reply
    0
    • W Offline
      W Offline
      Wilk
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        Thank you very much.

        I do not want my QDockWidget floating. How i remove it?

        1 Reply Last reply
        0
        • W Offline
          W Offline
          Wilk
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            Thank you very much.

            Is there a way to make a sidebar like the Qt Creator?

            1 Reply Last reply
            0
            • W Offline
              W Offline
              Wilk
              wrote on last edited by
              #6

              I'm sorry, but I don't know. Bt you may look in sources of Qt Creator for the answer.

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #7

                It has a lot of code and I can not find.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved