Ton van den Heuvel
Ton van den Heuvel

Reputation: 10528

Using QStyle to set global default minimum QPushButton height

Is it possible to define a default minimum height for a QPushButton through a custom application wide QStyle?

I know this can be achieved using stylesheets, but I rather not use them because of performance reasons.

Upvotes: 1

Views: 977

Answers (2)

Caleb Huitt - cjhuitt
Caleb Huitt - cjhuitt

Reputation: 14941

You might consider looking at the QApplication::globalStrut property, which is designed to provide a minimum size for any user-interactive UI element. Ideally, it would do what you want (and possibly more). However, I have seen times when this was ignored, either by the widget or the style drawing the widget, so in practice it has been somewhat less than useful.

Upvotes: 1

Live
Live

Reputation: 2001

There are two options I can see, here they are:

1) Suclass QStyle and set it to your application using

QApplication::setStyle(QStyle* yourstyle)

In QStyle, you must reimplement your own

void QStyle::drawPrimitive ( PrimitiveElement element, const QStyleOption * option, QPainter * painter, const QWidget * widget = 0 ) const  

2) Subclass QPushButton and use the method

QWidget::setMinimumHeight(int minHeight);

to set the minimum height and only use this subclass in the rest of your program.

Hope this helps.

Upvotes: 1

Related Questions