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

Zoltan Szalai defaultdict at gmail.com
Mon Nov 8 20:24:55 GMT 2010


'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/20101108/1856b507/attachment.html>


More information about the PyQt mailing list