Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 600
ProgAndPlay Avatar asked Nov 12 '17 23:11

ProgAndPlay


People also ask

How do I add an icon to the Start menu?

Adding New Icons to Start Menu and Taskbar Program icons can be added from the icons on the desktop or from the Start Menu. To “pin” an icon on the Desktop to your Start Menu put your cursor over the icon and “right click” to bring up the options menu. Then select “Pin to start” to add that icon to the Start Menu.


2 Answers

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

like image 144
eyllanesc Avatar answered Oct 10 '22 03:10

eyllanesc


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().

like image 35
Vincent Fourmond Avatar answered Oct 10 '22 03:10

Vincent Fourmond