c++qtubuntuqt5qicon

How to put system icons in menus?


I have run the menu example from Qt and there are no icons on menus, only text. Most apps (like pcmanfm and caja from Ubuntu) have similar icons, so I suppose they are system-wide and not application specific. How could I put icons in menu items? A code sample would be interesting.


Solution

  • To obtain the icons of the systems you must use the method QIcon::fromTheme()

    Example:

    newAct = new QAction(tr("&New"), this);
    newAct->setIcon(QIcon::fromTheme("document-new"));
    

    Qt uses as a backend to freedesktop icon, it has a rule in the names, the updated list of them can be found in the following link