How to put system icons in menus?
Asked Answered
C

2

6

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.

Coleen answered 12/11, 2017 at 23:52 Comment(0)
H
8

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

Hildegard answered 13/11, 2017 at 0:8 Comment(0)
U
2

The QIcon::fromTheme() function found in the other answer is unfortunately not portable to Mac or windows. You may have better luck using QStyle::standardIcon().

Undesigned answered 19/4, 2020 at 13:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.