[SOLVED] Icon shown in custom menu
Hi all,
I have a little problem with getting a icon shown in a QMenu,
i have read the docs, but i dont see what im doing wrong.
I found also a few topics here, but i still didnt solve it.
Here is the code:
- void Widget::setupMenu()
- {
- //Quit Action, makes the app quit.
- connect(Quit,SIGNAL(triggered()),this,SLOT(close()));
- //Pause Action, makes the video pause.
- connect(Pause,SIGNAL(triggered()),obj_MediaObject,SLOT(pause()));
- //Play Action, makes the video play.
- connect(Play,SIGNAL(triggered()),obj_MediaObject,SLOT(play()));
- //Stop Action, makes the video stop.
- connect(Stop,SIGNAL(triggered()),obj_MediaObject,SLOT(stop()));
- videoMenu->menuAction()->setIconVisibleInMenu(true);
- videoMenu->addAction(Play);
- videoMenu->menuAction()->setIcon(Play->icon());
- videoMenu->addAction(Pause);
- videoMenu->menuAction()->setIcon(Pause->icon());
- videoMenu->addAction(Stop);
- videoMenu->menuAction()->setIcon(Stop->icon());
- videoMenu->addSeparator();
- videoMenu->addAction(Quit);
- videoMenu->menuAction()->setIcon(Quit->icon());
- }
i call the menu with:
- {
- {
- videoMenu->exec( globalPos );
- }
- {
- }
- }
The menu is showing but the icons not.
Can somebody help me out to settle this?
Edit:
the path to the icons are ok.
because i allready used the .src file with the tray and window icon.
3 replies
Seem that your application has the attribute Qt::AA_DontShowIconsInMenus set. Watch if you come over a line like this:
You can try to reset the attribute like this:
If this is not applicable for your setup, you must enable the icons on the single actions:
- Quit->setIconVisibleInMenu(true);
- Play->setIconVisibleInMenu(true);
- Pause->setIconVisibleInMenu(true);
- Stop->setIconVisibleInMenu(true);
You should leave out the lines like this:
- videoMenu->menuAction()->setIcon(Stop->icon());
these just assign an icon of the menu entries to the menu itself.
Hi Volker,
Thanks for your reply.
Your second solution did help solving the problem.
Thanks for your help!!
My working code is now:
- void Widget::setupMenu()
- {
- //Quit Action, makes the app quit.
- Quit->setIconVisibleInMenu(true);
- connect(Quit,SIGNAL(triggered()),this,SLOT(close()));
- //Pause Action, makes the video pause.
- Pause->setIconVisibleInMenu(true);
- connect(Pause,SIGNAL(triggered()),obj_MediaObject,SLOT(pause()));
- //Play Action, makes the video play.
- Play->setIconVisibleInMenu(true);
- connect(Play,SIGNAL(triggered()),obj_MediaObject,SLOT(play()));
- //Stop Action, makes the video stop.
- Stop->setIconVisibleInMenu(true);
- connect(Stop,SIGNAL(triggered()),obj_MediaObject,SLOT(stop()));
- videoMenu->addAction(Play);
- videoMenu->addAction(Pause);
- videoMenu->addAction(Stop);
- videoMenu->addSeparator();
- videoMenu->addAction(Quit);
- }
You must log in to post a reply. Not a member yet? Register here!



