Hiding icons in menu bar
Solved
General and Desktop
-
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! -
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); } }
-
@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);