Results 1 to 1 of 1

Thread: Show different QSystemTrayIcon context menu on different shortcut key combination

  1. #1
    Join Date
    Apr 2012
    Location
    India.
    Posts
    88
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Exclamation Show different QSystemTrayIcon context menu on different shortcut key combination

    Hi All,
    I want to show two different menu on system tray icon based on "mouse right click" or "mouse right click + ctrl", i am using qt 4.7.3.

    First issue was keyboardModifiers function is not working for me and it says ctrl key is not pressed even though it is pressed and I can not use queryKeyboardModifiers as it is not supported in Qt 4.7.3, so I have written one function which uses platform specific API to detect ctrl key press in activate handler for system tray icon and that problem is solved now.

    but in System Tray icon activate signal handler, after detecting ctrl key press, when I tries to set new context menu it doesn't show new menu in popup immediately, but in the next mouse click it shows the updated popup menu, so my question is how to immediately update system tray icon context menu from activate signal handler.

    I am using windows 7, for this code.

    For some hint, i have pasted activate signal handler code here...

    //Sample code.
    void QMainWindow::iconActivated(QSystemTrayIcon::Activa tionReason reason)
    {
    switch (reason)
    {
    case QSystemTrayIcon::Context:
    {
    // this is utility function which uses platform specific code to identify if ctrl key is pressed or not.
    if (IsCtrlKeyPressed())
    {
    // For ctrl + right click show menu 1.
    m_pTrayIcon->setContextMenu(m_pMenu1);
    }
    else
    {
    // For only right click show menu 2.
    m_pTrayIcon->setContextMenu(m_pMenu2);
    }
    }
    break;

    default:
    break;
    }
    }

    Note that m_pTrayIcon is instance of QSystemTrayIcon.


    Thanks.
    Last edited by Rajesh.Rathod; 4th September 2013 at 09:37. Reason: updated contents

Similar Threads

  1. Replies: 2
    Last Post: 29th August 2012, 17:57
  2. Replies: 1
    Last Post: 4th November 2011, 11:25
  3. Replies: 4
    Last Post: 13th April 2009, 19:37
  4. Shortcut key for context menu
    By darshan.hardas in forum Qt Programming
    Replies: 1
    Last Post: 28th December 2008, 20:32
  5. Shortcut Context Problem
    By dvmorris in forum Qt Programming
    Replies: 4
    Last Post: 10th July 2007, 22:39

Tags for this Thread

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.