3

Using Qt 5.4 on OS X (Yosemite), I have a QAction that has an icon. I want the icon to show in the QToolbar that I add the action to. This works fine. However, I do NOT want the icon to show in the QMenu that I add the action to.

How do I do that?

David Burson
  • 2,947
  • 7
  • 32
  • 55

1 Answers1

5

You can use the Qt::AA_DontShowIconsInMenus attribute in your application or individually by QAction::setIconVisibleInMenu(bool visible). Straight from Qt's docs:

QApplication app(argc, argv);
app.setAttribute(Qt::AA_DontShowIconsInMenus);  // Icons are *no longer shown* in menus
// ...
QAction *myAction = new QAction();
// ...
myAction->setIcon(SomeIcon);
myAction->setIconVisibleInMenu(true);   // Icon *will* be shown in menus for *this* action.
spellmansamnesty
  • 469
  • 4
  • 10
  • Thanks very much, that did it! For reference: http://doc.qt.io/qt-5/qaction.html#iconVisibleInMenu-prop and http://doc.qt.io/qt-5/qt.html#ApplicationAttribute-enum – David Burson Apr 14 '15 at 15:25