QDockWidget setTitleBarWidget() example with "default" button style



  • 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.


  • Lifetime Qt Champion

    Hi,

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

    Can you explain your use case ?



  • 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.


  • Lifetime Qt Champion

    Then you can design your own and use setTitleBarWidget.



  • 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.


  • Moderators

    @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.



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.