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. Qt6 on Mac: setIcon on a QAction not working since 6.7.3
Forum Updated to NodeBB v4.3 + New Features

Qt6 on Mac: setIcon on a QAction not working since 6.7.3

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 266 Views
  • 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.
  • Leo SchubertL Offline
    Leo SchubertL Offline
    Leo Schubert
    wrote last edited by
    #1

    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

    jsulmJ I 2 Replies Last reply
    0
    • Leo SchubertL Leo Schubert

      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

      I Online
      I Online
      IgKh
      wrote last edited by
      #3

      @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 SchubertL 1 Reply Last reply
      3
      • Leo SchubertL Leo Schubert

        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

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote last edited by
        #2

        @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.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • Leo SchubertL Leo Schubert

          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

          I Online
          I Online
          IgKh
          wrote last edited by
          #3

          @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 SchubertL 1 Reply Last reply
          3
          • I IgKh

            @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 SchubertL Offline
            Leo SchubertL Offline
            Leo Schubert
            wrote last edited by
            #4

            @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!

            1 Reply Last reply
            1
            • Axel SpoerlA Axel Spoerl has marked this topic as solved

            • Login

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