3

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.

mrg95
  • 2,371
  • 11
  • 46
  • 89
  • 2
    In my projects using setFixedHeight on QToolBar works fine – Andre Nov 21 '16 at 07:08
  • @Andre Huh when I tried it it still didn't work. Did you need to do anything else? Like set a specific size policy or something? – mrg95 Nov 21 '16 at 16:18
  • 1
    No, I just set the height of the toolbar with the function I told you, nothing else: no size policy, no size constraint, no minimum height. Could be stupid but have you tried to call show() function on your QToolBar when you have set it up? – Andre Nov 22 '16 at 07:19
  • @Andre Okay THAT'S weird. I just tried it again and it's working now O_o. I'm trying to replicate the issue now and I can't. huh.... well thanks for your help! :) setFixedHeight is the answer – mrg95 Nov 22 '16 at 16:16

3 Answers3

7

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);
Draks
  • 323
  • 2
  • 9
1

toolbar->setFixedHeight(36) should work

Documentation here

Rômulo M. Farias
  • 1,483
  • 1
  • 15
  • 29
1

I just noticed the same problem with a QToolBar in my project, which didn't change its height although explicitly calling setMinimumHeight(64) on it. Turned out that delaying this into the main thread's eventloop using a singleShot QTimer helps:

# self is an instance of a QToolBar subclass
QtCore.QTimer.singleShot(0, lambda : self.setMinimumHeight(64))

(It's in PyQt5, but you should get the point.)

Jeronimo
  • 2,268
  • 2
  • 13
  • 28