mrg95
mrg95

Reputation: 2428

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:

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.

Upvotes: 3

Views: 7891

Answers (3)

Jeronimo
Jeronimo

Reputation: 2397

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

Upvotes: 1

Draks
Draks

Reputation: 323

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);

Upvotes: 7

Rômulo M. Farias
Rômulo M. Farias

Reputation: 1523

toolbar->setFixedHeight(36) should work

Documentation here

Upvotes: 1

Related Questions