Results 1 to 2 of 2

Thread: How to restrict setWindowState() for left-click on QSystemTrayIcon

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default How to restrict setWindowState() for left-click on QSystemTrayIcon

    I invoke a SLOT on click of QSystemTrayIcon activated SIGNAL. The slot does - setWindowState(Qt::WindowActive).
    Now I've added context menu which is appearing on right-click of tray-icon. But the Window is also showing on right-click of tray-icon. How do I restrict the setWindowState to be active only on left-click of the tray-icon ?
    Thank you.

  2. #2
    Join Date
    Oct 2012
    Posts
    132
    Thanks
    10
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: How to restrict setWindowState() for left-click on QSystemTrayIcon

    Just set the context menu using the "setContextMenu"-method of the QSystemTrayIcon.
    The activated signal is also emitted when the context menu is requested, so you have to check the activation reason before setting the window state.

    Qt Code:
    1. void MainWindow::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
    2. {
    3. switch (reason)
    4. {
    5. case QSystemTrayIcon::Trigger:
    6. case QSystemTrayIcon::DoubleClick:
    7. setWindowState(Qt::WindowActive);
    8. break;
    9. default:
    10. ;
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to Infinity for this useful post:

    rawfool (8th April 2013)

Similar Threads

  1. Replies: 7
    Last Post: 26th April 2012, 14:45
  2. Replies: 11
    Last Post: 15th October 2011, 22:51
  3. Mouse Right or Left click ???
    By anjanu in forum Qt Programming
    Replies: 9
    Last Post: 27th August 2011, 18:41
  4. programmatically right click on QSystemTrayIcon
    By noa l in forum Qt Programming
    Replies: 5
    Last Post: 10th April 2011, 13:42
  5. QSystemTrayIcon on click() ?
    By probine in forum Qt Programming
    Replies: 4
    Last Post: 25th January 2007, 08:43

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
  •  
Qt is a trademark of The Qt Company.