Qt6 on Mac: setIcon on a QAction not working since 6.7.3
-
Hi, The following code works on Windows up to Qt6.9.2 but is broken on Mac since 6.7.3 (6.7.2 was the latest working version), the image "bart.png" (must be in the same directory) isn't shown in addition to the "Hello Bart" text in the contextual popup menu. (Same for menu QAction images if the menu is in the menu bar).
#include <QtGui> #include <QApplication> #include <QMenu> #include <QLineEdit> #include <QDebug> #include <QDir> class WLineEdit : public QLineEdit { public: WLineEdit(QWidget *parent) : QLineEdit(parent) { } void contextMenuEvent( QContextMenuEvent * e ) { QPointer<QMenu> pop = new QMenu( this ); QPixmap pix=QPixmap("bart.png"); QAction* ac = pop->addAction( "Hallo Bart"); ac->setIcon(pix); pop->exec(e->globalPos()); } }; int main(int argc, char**argv) { QApplication app(argc, argv); qDebug() << "current path:" << QDir::currentPath(); WLineEdit le(0); le.show(); return app.exec(); }
Did someone encounter the same problem ?
Regards , Leo -
Hi, The following code works on Windows up to Qt6.9.2 but is broken on Mac since 6.7.3 (6.7.2 was the latest working version), the image "bart.png" (must be in the same directory) isn't shown in addition to the "Hello Bart" text in the contextual popup menu. (Same for menu QAction images if the menu is in the menu bar).
#include <QtGui> #include <QApplication> #include <QMenu> #include <QLineEdit> #include <QDebug> #include <QDir> class WLineEdit : public QLineEdit { public: WLineEdit(QWidget *parent) : QLineEdit(parent) { } void contextMenuEvent( QContextMenuEvent * e ) { QPointer<QMenu> pop = new QMenu( this ); QPixmap pix=QPixmap("bart.png"); QAction* ac = pop->addAction( "Hallo Bart"); ac->setIcon(pix); pop->exec(e->globalPos()); } }; int main(int argc, char**argv) { QApplication app(argc, argv); qDebug() << "current path:" << QDir::currentPath(); WLineEdit le(0); le.show(); return app.exec(); }
Did someone encounter the same problem ?
Regards , Leo@Leo-Schubert it isn't broken, it is just that since this version
Qt::AA_DontShowIconsInMenus
application attribute is enabled on default on macOS. You need to disable it yourself if you want them.Under the Big Sur design system, Mac applications customarily don't use icons in menus, so it made sense. They do make a comeback in the "Liquid Glass" design system of the upcoming macOS Tahoe.
-
Hi, The following code works on Windows up to Qt6.9.2 but is broken on Mac since 6.7.3 (6.7.2 was the latest working version), the image "bart.png" (must be in the same directory) isn't shown in addition to the "Hello Bart" text in the contextual popup menu. (Same for menu QAction images if the menu is in the menu bar).
#include <QtGui> #include <QApplication> #include <QMenu> #include <QLineEdit> #include <QDebug> #include <QDir> class WLineEdit : public QLineEdit { public: WLineEdit(QWidget *parent) : QLineEdit(parent) { } void contextMenuEvent( QContextMenuEvent * e ) { QPointer<QMenu> pop = new QMenu( this ); QPixmap pix=QPixmap("bart.png"); QAction* ac = pop->addAction( "Hallo Bart"); ac->setIcon(pix); pop->exec(e->globalPos()); } }; int main(int argc, char**argv) { QApplication app(argc, argv); qDebug() << "current path:" << QDir::currentPath(); WLineEdit le(0); le.show(); return app.exec(); }
Did someone encounter the same problem ?
Regards , Leo@Leo-Schubert Did you check whether pix is a valid QPixmap (https://doc.qt.io/qt-6/qpixmap.html#isNull)?
Using relative paths to load resources like pixmaps is dangerous. Usually one uses resource files. -
Hi, The following code works on Windows up to Qt6.9.2 but is broken on Mac since 6.7.3 (6.7.2 was the latest working version), the image "bart.png" (must be in the same directory) isn't shown in addition to the "Hello Bart" text in the contextual popup menu. (Same for menu QAction images if the menu is in the menu bar).
#include <QtGui> #include <QApplication> #include <QMenu> #include <QLineEdit> #include <QDebug> #include <QDir> class WLineEdit : public QLineEdit { public: WLineEdit(QWidget *parent) : QLineEdit(parent) { } void contextMenuEvent( QContextMenuEvent * e ) { QPointer<QMenu> pop = new QMenu( this ); QPixmap pix=QPixmap("bart.png"); QAction* ac = pop->addAction( "Hallo Bart"); ac->setIcon(pix); pop->exec(e->globalPos()); } }; int main(int argc, char**argv) { QApplication app(argc, argv); qDebug() << "current path:" << QDir::currentPath(); WLineEdit le(0); le.show(); return app.exec(); }
Did someone encounter the same problem ?
Regards , Leo@Leo-Schubert it isn't broken, it is just that since this version
Qt::AA_DontShowIconsInMenus
application attribute is enabled on default on macOS. You need to disable it yourself if you want them.Under the Big Sur design system, Mac applications customarily don't use icons in menus, so it made sense. They do make a comeback in the "Liquid Glass" design system of the upcoming macOS Tahoe.
-
@Leo-Schubert it isn't broken, it is just that since this version
Qt::AA_DontShowIconsInMenus
application attribute is enabled on default on macOS. You need to disable it yourself if you want them.Under the Big Sur design system, Mac applications customarily don't use icons in menus, so it made sense. They do make a comeback in the "Liquid Glass" design system of the upcoming macOS Tahoe.
@IgKh Thanks, I did find the release notes of Qt6.7.3 stating
a2aa1f81a81 Determine Qt::AA_DontShowIconsInMenus default value based on platform The default value of Qt::AA_DontShowIconsInMenus is now determined based on the platform. On macOS icons will not show by default. To override, use QAction.iconVisibleInMenu for individual menu actions, or set Qt::AA_DontShowIconsInMenus to false.
As it did change from 6.7.2->6.7.3 my assumption was that this was rather unintended ...Nevermind. issue solved. Thanks again!
-
A Axel Spoerl has marked this topic as solved