[PyQt] problem with QSystemTrayIcon

Mark Summerfield mark at qtrac.eu
Thu Feb 21 11:26:15 GMT 2008


On 2008-02-21, Rafał Zawadzki wrote:
> Hello. I am using python-qt4 on kubuntu 7.10.
>
> I found a very strange behaviour in the below code:
>
> * after exit (choose Quit from menu on systray icon application
> segfaults)

I don't get the segfault using Qt 4.3.3; but there was a problem with Qt
4.3.1 of a harmless segfault at termination.

> * showMessage is showed centered on the screen - in class
> reference it is connected with systracicon.

You shouldn't call showMessage() until after the event loop has started.
One solution is to use a single shot timer with a timeout of 0.

Aside: AFAIK there is no way to intercept a left-click with
QSystemTrayIcon; it is a QObject subclass (but not a QWidget subclass)
so you can't reimplement either mouse or keyboard handlers. So if you
want interaction it can only be by providing menu options.

>
> I suppose that these above are bugs. Anyone could check this?
>
> import sys
> from PyQt4.QtCore import SIGNAL
> from PyQt4.QtGui import QApplication
> from PyQt4.QtGui import QIcon
> from PyQt4.QtGui import QMenu
> from PyQt4.QtGui import QAction
> from PyQt4.QtGui import QSystemTrayIcon
> from PyQt4.QtCore import QString
> from PyQt4.QtCore import SLOT
>
> if __name__ == "__main__":
>     app = QApplication(sys.argv)
>     plik = QString("/usr/share/icons/crystalsvg/16x16/apps/wine.png")
>     menu = QMenu()
>     quitAction = menu.addAction('Quit')
>     sicon = QIcon(plik)
>     tray = QSystemTrayIcon(sicon)
>     tray.setContextMenu(menu)
>     tray.show()
>     quitAction.connect(quitAction, SIGNAL("triggered()"), app,
> SLOT("quit()")) #atray.connect(tray, SIGNAL("clicked()"))
>     tray.setToolTip("Ale czad!")
>     tray.showMessage("Title of the message", "Body of the message")
>     sys.exit(app.exec_())
>
> Regards,



-- 
Mark Summerfield, Qtrac Ltd., www.qtrac.eu




More information about the PyQt mailing list