johngull
johngull

Reputation: 819

QSystemTrayIcon activated signal: DoubleClick without Trigger

I want to show context menu on left click and run app on double click. For this i have next code:

...
connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(slotActivated(QSystemTrayIcon::ActivationReason)));
...
void MyTray::slotActivated(ActivationReason reason)
{
    if(reason==QSystemTrayIcon::DoubleClick)
        startApp();
    else
        if(reason==QSystemTrayIcon::Trigger
           || reason==QSystemTrayIcon::MiddleClick)
                contextMenu()->popup(QCursor::pos());
}

It works, but for double click case i got two slot calls - one for Trigger and only then for DoubleClick. As result context menu shown and hidding in a moment. Is there is a way to avoid this?

Upvotes: 2

Views: 1113

Answers (1)

TheDarkKnight
TheDarkKnight

Reputation: 27611

Rather than using slotActivated, you need to handle the mouse events.

Whilst these aren't directly available in QSystemTrayIcon, it does allow you to install an event filter and handle the mouse events from there.

Upvotes: 4

Related Questions