How to change menu's icon's size

  • i want to change menu's icon's size to 32*32, how to do it .

  • If you are using QToolBar, it has a iconSize property. For menu, though, refer "link here":

  • Moderators

    AFAIK QMenu only gets it's icon size from the style it has set.
    So you would need to subclass "QProxyStyle": and reimplement pixelMetric() method:

    Something like this:
    class MyProxyStyle : public QProxyStyle
    int pixelMetric(PixelMetric metric, const QStyleOption * option = 0, const QWidget * widget = 0 ) const
    if (metric == QStyle::PM_SmallIconSize)
    return 32;
    return QProxyStyle::pixelMetric(metric, option, widget);
    Haven't tried it though.

    Please also note the hint in the docs:
    Warning: The common styles provided by Qt will respect this hint, because they call QStyle::proxy(), but there is no guarantee that QStyle::proxy() will be called for user defined or system controlled styles. It would not work on a Mac, for example, where menus are handled by the operating system.

  • thank you .i try it

  • ya,i try your can change icon's size,but when icon's size get big,the QMenu'icon can covered QMenu's text,how to set space
    between icon and text.
    i find a stylesheet's code ,QMenu::item { padding: xx xx xx xx;},it can change space bewteen icon and text. it can use code instead of stylesheet?

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.