Search code examples
c++qtqtstylesheetsqtoolbar

QToolBar Change Height


In my project I have a QToolBar with default size and size policy. I want to increase the height of the toolbar to 36px.

So far I have tried:

  • Setting a stylesheet property to the toolbar: height: 36px;
  • Setting the toolbar object's size policy to fixed: toolBar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
  • Setting the minimumHeight: toolBar->setMinimumHeight(36);
  • Setting the layout size constraint toolBar->layout()->setSizeConstraint(QLayout::SetMinimumSize)
  • All of those at once

And nothing increases the height of the toolbar. The only thing that works is increasing the size of the QToolButton objects within the bar, but this is not what I want to do. I only want the toolbar itself taller.

Any suggestions? Thanks for your time.

EDIT: My current solution was to add a margin to the QToolButton objects in the toolbar. I still don't like this because I have varying object types in the toolbar.... frustrating.


Solution

  • toolBar->setFixedHeight(36); - works well.

    But if I set icon size after this:

    toolBar->setFixedHeight(36); 
    toolBar->setIconSize(QSize(10, 10));
    

    height breaks down. Also it happens if I set icon size via stylesheet.

    Changing of calls order helps:

    toolBar->setIconSize(QSize(10, 10));
    toolBar->setFixedHeight(36);