programmatically right click on QSystemTrayIcon
Hi All
I will appreciate your help in this matter:
Normally, the context menu of a QSystemTRayIcon will appear when user right-click on the icon.
i want it to show also when left click. So I catch "activated" with "trigger".
Now what do i do? Sure enough you will say this line is good: menu->show().
However - if user makes a left click before any right click action was performed - the context menu is opened in 0,0 position instead of near the icon.
Since the system tray can be located up or down the desktop - i do not want to compute the desired location myself. I would rather immitate the "right click" action programmatically, as if the user right clicked the middle of the icon.
I do not know how to do that - I searched the net and try many things.. but nothing worked. Please note the QSystenTrayIcon is not a QWidget...
I would appreciate any help - and if you have a piece of code that works i will be very greatfull to see it..
Thanks
Noa
Re: programmatically right click on QSystemTrayIcon
I did it in this way
Code:
{
{
myClip.setWindowFlags(Qt::WindowStaysOnTopHint/* | Qt::FramelessWindowHint */);
myClip.show();
}
trayMenu->show();
}
Re: programmatically right click on QSystemTrayIcon
Thank you for your reply.
But as far as i can tell you did exactly what i did , which is "trayMeny->show" (Did i understand correct?). So I am still with the same problem. If the menu has never shown before - it will be opened in (0,0) position.
Any other ideas?
Re: programmatically right click on QSystemTrayIcon
I think it is quite simple. Call QMenu::popup() instead of QMenu::show().
Example:
Code:
{
switch(reason)
{
trayContexMenu
->popup
(QCursor::pos());
break;
// ....
}
}
Hope it's helps..
Re: programmatically right click on QSystemTrayIcon
hello viulskiez
It looks as if it did the trick... !!!
I was not aware of this option ,Thank you very much :-)
Noa
Re: programmatically right click on QSystemTrayIcon