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. QDockWidget setTitleBarWidget() example with "default" button style

QDockWidget setTitleBarWidget() example with "default" button style

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 7.3k Views
  • 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.
  • gde23G Offline
    gde23G Offline
    gde23
    wrote on last edited by
    #1

    Hello,

    I want to add a maximize-button to the QDockWidget titlebar that calls QDockWidget::showFullScreen();

    However I cannot find any example that shows how to set up a custom titlebar widget including buttons that look like usually. (the widget should contain all the things that are there by default (icon, title-string, close and dock button) as well as the additional maximize button.

    I can add buttons like this

    QWidget *title_bar = new QWidget();
    QHBoxLayout* layout = new QHBoxLayout();
    title_bar->setLayout(layout);
    layout->addWidget(new QToolButton());
    

    but then they do not look like the auto generated ones when using the default titlebar.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Dock widgets are not meant to show standard widget decoration and thus controls.

      Can you explain your use case ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • gde23G Offline
        gde23G Offline
        gde23
        wrote on last edited by
        #3

        Hi,

        I simply want to add a maximize button to the dockWidget so i can undock it and then click on the button to make it fullscreen.
        alt text
        Like the button on the mainwindow (red circle) also on the dockwidget.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Then you can design your own and use setTitleBarWidget.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • gde23G Offline
            gde23G Offline
            gde23
            wrote on last edited by
            #5

            But how do i make the buttons on my own titlebarwidget look like those in the screenshot above?
            I can get the functionality I need by doing something like this:

            QWidget *title_bar = new QWidget();
            QHBoxLayout* layout = new QHBoxLayout();
            title_bar->setLayout(layout);
            layout->addWidget(new QPushButton());
            dock_widget->setTitleBarWidget(title_bar);
            

            but then the button will look like a normal button and not like the other titelbar-buttons on the dock widgets.
            So the question is where the style for the buttons that are used for the dockwidget's titelbar come from and how i can apply the style/icon to my own buttons.

            raven-worxR 1 Reply Last reply
            0
            • gde23G gde23

              But how do i make the buttons on my own titlebarwidget look like those in the screenshot above?
              I can get the functionality I need by doing something like this:

              QWidget *title_bar = new QWidget();
              QHBoxLayout* layout = new QHBoxLayout();
              title_bar->setLayout(layout);
              layout->addWidget(new QPushButton());
              dock_widget->setTitleBarWidget(title_bar);
              

              but then the button will look like a normal button and not like the other titelbar-buttons on the dock widgets.
              So the question is where the style for the buttons that are used for the dockwidget's titelbar come from and how i can apply the style/icon to my own buttons.

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by raven-worx
              #6

              @gde23
              i don't know if it returns the desired icon, but worth a try:

              QIcon icon = widget->style()->standardIcon(QStyle::SP_TitleBarMaxButton, 0, widget);
              button->setIcon( icon );
              

              On what platform/desktop are you running on?

              Otherwise (if possible) you can set a breakpoint in the Qt source code and step through the code and check where the icon is taken from.

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              4
              • gde23G Offline
                gde23G Offline
                gde23
                wrote on last edited by
                #7

                @raven-worx: Thanks a lot. that's exactly what i was looking for

                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