tags:

views:

40

answers:

2

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.

+1  A: 

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.

Live
How is solution 1) going to work? Layouts need to know about the size as well, only drawing the widget at a certain size does not mean that the widget actually has that size. Solution 2) should work but is cumbersome :( I'll stick with hardcoding all sizes in the UI files for now.
Ton van den Heuvel
+1  A: 

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.

Caleb Huitt - cjhuitt
Thanks! Exactly what I was looking for, I'll try to see if it works for push buttons.
Ton van den Heuvel
Works for QPushButton :)
Ton van den Heuvel