qmenu icon size

  • Is it possible to change the qmenu icon size using a style sheet?

  • Lifetime Qt Champion


    Take a look here for tips on how to customize a QMenu. Note that depending on the OS you are using, these modifications might not apply e.g. on OS X.

  • Moderators

    The icon size of a QMenu is taken from the set style and not from a widget property.

    So for example you can't use something like

    QMenu {
    qproperty-iconSize: 16px 16px;

    Instead it's taken from the set (platform-)style itself.

    So you can try to implement a QProxyStyle:

    class MyProxyStyle: public QProxyStyle
                   MyProxyStyle(QStyle * style = 0) : QProxyStyle(style)
    	       MyProxyStyle(const QString & key) : QProxyStyle(key)
    	       virtual int pixelMetric(QStyle::PixelMetric metric, const QStyleOption * option = 0, const QWidget * widget = 0 ) const
    		        switch ( metric )
                                  case QStyle::PM_SmallIconSize:
                                           return 20;
    			              return QProxyStyle::pixelMetric( metric, option, widget );

    Not sure if it will be ignored when your widget also has a (inherited) QStylesheetStyle set. Since a QStylesheetStyle is also a proxy style and has a special handling in QWidget.

  • @raven-worx Thanks. Is there any chance of adding functions to QMenu, such as setTextSize and setIconSize? Or maybe just one of those, which automatically sets the other. (I'm aware we can set the text size via style sheet.)

  • Lifetime Qt Champion

    Very highly unlikely, Qt follows the platform style and thus the settings your users have.

    Note that modifying menus text size and icon size is likely to interfere with most platforms human interface guidelines which is usually a bad idea.

Log in to reply