Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. qmenu icon size
Forum Update on Monday, May 27th 2025

qmenu icon size

Scheduled Pinned Locked Moved General and Desktop
qmenustylesheet
6 Posts 4 Posters 7.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ravasR Offline
    ravasR Offline
    ravas
    wrote on last edited by
    #1

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

    raven-worxR 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • ravasR ravas

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

        raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

        @ravas
        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
        {
        	Q_OBJECT
        
        	public:
                       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;
                                      default:
        			              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.

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        ravasR 1 Reply Last reply
        1
        • raven-worxR raven-worx

          @ravas
          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
          {
          	Q_OBJECT
          
          	public:
                         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;
                                        default:
          			              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.

          ravasR Offline
          ravasR Offline
          ravas
          wrote on last edited by
          #4

          @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.)

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            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.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • ewerybodyE Offline
              ewerybodyE Offline
              ewerybody
              wrote on last edited by
              #6

              Whow! I just stumbled across this after all these years. I remember I had this problem once and now again. This time I actually managed to solve it somewhat. It IS kinda weird tho and should receive some love at least documentation-wise.

              The key is: You need to style QMenu AND QMenu::item If you just set the icon size via:

              QMenu {icon-size: 40px;}
              

              it will remain ignored until you also set something like

              QMenu::item {background: transparent;}
              

              Unfortunately this resets the menu stylesheet and you need to do something about the hover state to make it usable. But well.
              Seems this works for me.
              Can someone confirm please?

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved