Results 1 to 6 of 6

Thread: programmatically right click on QSystemTrayIcon

  1. #1
    Join Date
    Dec 2010
    Posts
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question 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

  2. #2
    Join Date
    Dec 2009
    Posts
    18
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: programmatically right click on QSystemTrayIcon

    I did it in this way
    Qt Code:
    1. void supertray::click_on_icon(QSystemTrayIcon::ActivationReason motivo)
    2. {
    3. if (motivo == QSystemTrayIcon::DoubleClick)
    4. {
    5. myClip.setWindowFlags(Qt::WindowStaysOnTopHint/* | Qt::FramelessWindowHint */);
    6. myClip.show();
    7. }
    8.  
    9. else if ((motivo == QSystemTrayIcon::Context) || (motivo == QSystemTrayIcon::Trigger))
    10. trayMenu->show();
    11. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Dec 2010
    Posts
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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?

  4. #4
    Join Date
    Jul 2010
    Location
    Indonesia
    Posts
    83
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: programmatically right click on QSystemTrayIcon

    I think it is quite simple. Call QMenu::popup() instead of QMenu::show().


    Example:
    Qt Code:
    1. void MyWidget::activated(QSystemTrayIcon::ActivationReason reason)
    2. {
    3. switch(reason)
    4. {
    5. case QSystemTrayIcon::Trigger:
    6. trayContexMenu->popup(QCursor::pos());
    7. break;
    8. // ....
    9. }
    10.  
    11. }
    To copy to clipboard, switch view to plain text mode 

    Hope it's helps..

  5. The following user says thank you to viulskiez for this useful post:

    ZikO (3rd September 2012)

  6. #5
    Join Date
    Dec 2010
    Posts
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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

  7. #6
    Join Date
    Jul 2010
    Location
    Indonesia
    Posts
    83
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: programmatically right click on QSystemTrayIcon

    You are welcome.

Similar Threads

  1. Programmatically Dock
    By venkateshhegde in forum Newbie
    Replies: 4
    Last Post: 14th February 2011, 00:35
  2. How to programmatically add attachments to emails in Qt
    By Praveena pb in forum Qt Programming
    Replies: 2
    Last Post: 25th November 2010, 19:34
  3. Creating a button programmatically
    By Luc4 in forum Newbie
    Replies: 1
    Last Post: 27th January 2010, 10:30
  4. [?] Input text programmatically
    By XuTMAH in forum Newbie
    Replies: 3
    Last Post: 24th September 2007, 16:47
  5. QSystemTrayIcon on click() ?
    By probine in forum Qt Programming
    Replies: 4
    Last Post: 25th January 2007, 08:43

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.