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. Setting QIcon with svg file as a QAction icon problem
QtWS25 Last Chance

Setting QIcon with svg file as a QAction icon problem

Scheduled Pinned Locked Moved Solved General and Desktop
qt5macosxqactionqiconsvg
7 Posts 3 Posters 18.2k 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.
  • R Offline
    R Offline
    rzhurov
    wrote on 9 Mar 2016, 15:23 last edited by rzhurov 3 Oct 2016, 08:21
    #1

    I have an issue with setting icon for a QAction when image file is an svg image.
    For example:

    QMenu menu("Test");
    QAction* testAction = menu.addAction("Test action");
    testAction->setIcon(QIcon("path_to_svg_file/icon.svg"));
    

    This works fine in qt 4.8.1, but in qt 5.5.1 and 5.6.0rc it does not.
    Tested on Mac OS X 10.10.5 and 10.11.
    Also I have to mention that svg module is surely present in tested qt versions because setting QIcon with an svg image for, for example, QToolButton works good.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 9 Mar 2016, 21:39 last edited by
      #2

      Hi and welcome to devnet,

      Where are you using that menu ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      R 1 Reply Last reply 10 Mar 2016, 08:53
      0
      • S SGaist
        9 Mar 2016, 21:39

        Hi and welcome to devnet,

        Where are you using that menu ?

        R Offline
        R Offline
        rzhurov
        wrote on 10 Mar 2016, 08:53 last edited by rzhurov 3 Oct 2016, 08:53
        #3

        @SGaist thank you for your answer, I've made further investigation and now able to provide you with additional information.

        It seems that behaviour described above actually depends on where QMenu object is used.
        I've tested it with application's menu, tray icon menu and drop-down menu of QToolButton, and results are as follows: icon is visible only in QToolButton's menu.

        Here is a full test example :

        #include <QApplication>
        #include <QMenuBar>
        #include <QToolButton>
        #include <QSystemTrayIcon>
        
        int main(int argc, char *argv[])
        {
            QApplication a(argc, argv);
        
            //create test QMenu
            QMenu* menuPtr = new QMenu("Test menu");
        
            //create test QAction with an svg icon
            QAction* actionPtr = menuPtr->addAction("Test action");
            actionPtr->setIcon(QIcon(":/i/icon.svg"));
            actionPtr->setIconVisibleInMenu(true);
        
            //add test menu to QMenuBar
            QMenuBar *menuBarPtr = new QMenuBar();
            menuBarPtr->addMenu(menuPtr);
        
            QWidget* w = new QWidget();
        
            //add test menu to QToolButton
            QToolButton* toolButtonPtr = new QToolButton(w);
            toolButtonPtr->setText("Test button");
            QObject::connect(toolButtonPtr, SIGNAL(pressed()), toolButtonPtr, SLOT(showMenu()));
            toolButtonPtr->setMenu(menuPtr);
            w->show();
        
            //add test menu to QSystemTrayIcon
            QSystemTrayIcon* trayIconPtr = new QSystemTrayIcon();
            trayIconPtr->setContextMenu(menuPtr);
            trayIconPtr->show();
        
            return a.exec();
        }
        
        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 12 Mar 2016, 23:11 last edited by
          #4

          @rzhurov said:

          actionPtr->setIcon(QIcon(":/i/icon.svg"));

          Replace that by:
          actionPtr->setIcon(QPixmap(":/i/icon.svg"));

          The backend engine used are different when adding a file or a pixmap.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          R 1 Reply Last reply 14 Mar 2016, 09:23
          0
          • S SGaist
            12 Mar 2016, 23:11

            @rzhurov said:

            actionPtr->setIcon(QIcon(":/i/icon.svg"));

            Replace that by:
            actionPtr->setIcon(QPixmap(":/i/icon.svg"));

            The backend engine used are different when adding a file or a pixmap.

            R Offline
            R Offline
            rzhurov
            wrote on 14 Mar 2016, 09:23 last edited by
            #5

            @SGaist thank you, it works.
            I suppose it is a bug that should be reported?

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 14 Mar 2016, 21:00 last edited by
              #6

              I don't know if it's a bug or a missing feature but making it known to the devs is a good idea. You should check the bug report system to see if it's something already known. If not then please open a new report providing a minimal compellable example that shows the behavior.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • D Offline
                D Offline
                DRydh
                wrote on 2 Oct 2016, 15:15 last edited by
                #7

                I saw that this bug has been reported.

                1 Reply Last reply
                0

                • Login

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