Search code examples
qt-creatorqt-designerqmenuqactionqicon

How to add icons to QMenu in Qt Creator?


I have several *.png icon files like new.png, open.png etc. I added these icons to my main menu in the QtCreator as following:

  1. Click on corresponding QAction in desgin mode
  2. In that actions property window --> QAction --> icon --> Select file...
  3. Select e.g. new.png
  4. Enter

Now, I can see that icon next to the newAction QAction object in the Qt creator design mode as here enter image description here

The visible and iconVisibleInMenu is both checked in the properties window!

But, when I build that project and run my application, the icon is not there?? Why or what am I missing?


Solution

  • Ok 1. I have to add a resource file via right click -> add.. -> Qt -> Resource file 2. Click on that new resource file and add folder with the icons.

    Now, you are also able to select a resource in your whole code.