[PyQt] How can i capture activated signal of Tray Icon??

Jebagnana Das jebagnanadas at gmail.com
Tue Nov 9 14:08:29 GMT 2010


Thanks Zoltan.. It did help a lot.. But if i want to capture single click
and double click events of the mouse separately i'm afraid this can't be
used..

def onTrayIconActivated(self, reason):
        if reason == QSystemTrayIcon.DoubleClick:
            print('tray icon double clicked')

        if reason == QSystemTrayIcon.Trigger:
            print("Tray icon single clicked")

If i double click the tray icon it executes both if conditions. Any way of
resolving this?. Thanks again..

On Tue, Nov 9, 2010 at 11:27 AM, <pyqt-request at riverbankcomputing.com>wrote:

>
> 'activated' is a signal of QSystemTrayIcon.
> you have to connect it to a slot (the onTrayIconActivated method in this
> case) in order to catch it.
> i highly suggest this reading before step forward:
>
> http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/pyqt4ref.html#new-style-signal-and-slot-support
>
> minimal working example here:
>
> import sys
> from PyQt4.QtCore import *
> from PyQt4.QtGui import *
>
> class MainWindow(QMainWindow):
>
>     def __init__(self, parent=None):
>         super(MainWindow, self).__init__(parent)
>
>         self.trayIcon = QSystemTrayIcon(self)
>         self.trayIcon.activated.connect(self.onTrayIconActivated)
>         self.trayIcon.show()
>
>     def onTrayIconActivated(self, reason):
>         if reason == QSystemTrayIcon.DoubleClick:
>             print 'tray icon double clicked'
>
> if __name__ == "__main__":
>     app = QApplication(sys.argv)
>     w = MainWindow()
>     w.show()
>     sys.exit(app.exec_())
>
>
> hope it helps
>
> bests
> Zoltan
>
>
>
> On 2010.11.08. 15:54, Jebagnana Das wrote:
> > Hello all,
> >
> >         Based on this example
> >
> http://www.saltycrane.com/blog/2008/01/how-to-capture-tab-key-press-event-with/
> > i've created a class as below
> >
> > class SystemTrayIcon(QtGui.QSystemTrayIcon):
> >
> >     def __init__(self,parent,objectName):
> >
> >         QtGui.QSystemTrayIcon.__init__(self,parent)
> >
> >         self.setObjectName(objectName)
> >
> >         print("Tray icon created")
> >
> >     def activated(self,reason):
> >
> >         if reason==QtGui.QSystemTrayIcon.DoubleClick:
> >
> >             print("Tray icon Double clicked")
> >
> > After creating an object for this class when i double click the tray
> > icon nothing happens. Any idea of what am i missing here?? Thanks..
> >
> >
> > _______________________________________________
> > PyQt mailing list    PyQt at riverbankcomputing.com
> > http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20101109/a8a0e01d/attachment.html>


More information about the PyQt mailing list