Test doubleclick on QSystemTrayIcon



  • I'm trying to test that my application gets activated when the system tray icon is double-clicked.
    Since QSystemTrayIcon is not derived from QWidget, I can't use QTest::mouseDClick.

    The only solution i have found sofar is using the windows funtions SetCursorPos and mouse_event, but it seems very brittle to have to move the cursor to a certain position and have it double-click there.

    Is there a QT way of doing this instead?

    BR. Kenneth.



  • Tray->connect(Tray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this,
                        SLOT(RestoreWindowTrigger(QSystemTrayIcon::ActivationReason)));
    
    void MainWindow::RestoreWindowTrigger(QSystemTrayIcon::ActivationReason RW)
    {
        if(RW == QSystemTrayIcon::DoubleClick)
        {
            show();
            activateWindow();
        }
    }
    


  • @kjoo said in Test doubleclick on QSystemTrayIcon:

    I'm trying to test that my application gets activated when the system tray icon is double-clicked.

    you can manually emit the signal: tray->activated(QSystemTrayIcon::DoubleClick);

    I know it's not exactly the same as actually double clicking but if you are not reimplementing QSystemTrayIcon then you do not need to test the link between click and signal as it is already done in Qt's own tests



  • @VRonin Thanks. I think this is a good solution.



  • @ARASHz4 Thanks. I already had that written. I was trying to make a unit-test that tested it.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.