【问题标题】:Qt 5.4 OS X how to use a QAction in both a QMenu and a QToolBar, but show the icon only in the QToolbarQt 5.4 OS X 如何在 QMenu 和 QToolBar 中使用 QAction,但仅在 QToolbar 中显示图标
【发布时间】:2015-04-13 21:27:37
【问题描述】:

在 OS X (Yosemite) 上使用 Qt 5.4,我有一个带有图标的 QAction。我希望图标显示在我添加操作的QToolbar 中。这工作正常。但是,我不希望图标显示在我添加操作的 QMenu 中。

我该怎么做?

【问题讨论】:

    标签: macos qt qt5 qmenu qaction


    【解决方案1】:

    您可以在应用程序中使用Qt::AA_DontShowIconsInMenus 属性,也可以通过 QAction::setIconVisibleInMenu(bool visible) 单独使用。直接来自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.
    
    猜你喜欢
    • 1970-01-01
    • 2020-08-28
    • 2022-10-18
    • 2020-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多