开发者

Using QStyle to set global default minimum QPushButton height

开发者 https://www.devze.com 2023-01-18 15:15 出处:网络
Is it possible to define a default minimum height for a QPushButton through a custom application wide QStyle?

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

I know this can be achie开发者_C百科ved using stylesheets, but I rather not use them because of performance reasons.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消