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. Hiding icons in menu bar
Qt 6.11 is out! See what's new in the release blog

Hiding icons in menu bar

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 6.5k Views 1 Watching
  • 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.
  • P Offline
    P Offline
    pbe
    wrote on last edited by
    #1

    Is there a way to hide the icons in the main menu bar (for example to be more compliant to the OS X way to show menus) in a QWidget (with QMainWindow) application?

    Code like this will also remove the icons of the main toolbar.

        QList<QMenu*> lst;
        lst = ui->menuBar->findChildren<QMenu*>();
        foreach (QMenu* m, lst) {
            foreach (QAction* a, m->actions()) {
                a->setIcon(QIcon());
            }
        }
    

    I'm asking for this issue: OS X: Icons in menus
    Thank you for helping!

    1 Reply Last reply
    0
    • Chris KawaC Online
      Chris KawaC Online
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Assuming the icon sizes in the menu and on the toolbar are different you can add an empty pixmap for the size in the menu. Something like this:

      QPixmap dummy (16,16); //or whatever the size of the menu icon is on OS X
      dummy.fill(Qt::transparent);
      
      QList<QMenu*> lst = ui->menuBar->findChildren<QMenu*>();
      foreach (QMenu* m, lst) {
          foreach (QAction* a, m->actions()) {
              QIcon icon = a->icon();
              icon.addPixmap(dummy);
              a->setIcon(icon);
          }
      }
      
      P 1 Reply Last reply
      0
      • Chris KawaC Chris Kawa

        Assuming the icon sizes in the menu and on the toolbar are different you can add an empty pixmap for the size in the menu. Something like this:

        QPixmap dummy (16,16); //or whatever the size of the menu icon is on OS X
        dummy.fill(Qt::transparent);
        
        QList<QMenu*> lst = ui->menuBar->findChildren<QMenu*>();
        foreach (QMenu* m, lst) {
            foreach (QAction* a, m->actions()) {
                QIcon icon = a->icon();
                icon.addPixmap(dummy);
                a->setIcon(icon);
            }
        }
        
        P Offline
        P Offline
        pbe
        wrote on last edited by
        #3

        @Chris-Kawa, thank you for your reply! Your solution caused all menu entries to have as width of a few pixels. :)

        I found salvation in https://forum.qt.io/topic/24960/solved-osx-menu-icons/2

        This code worked:

        QApplication::instance()->setAttribute(Qt::AA_DontShowIconsInMenus, true);
        
        1 Reply Last reply
        2

        • Login

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