[PyQt] problem with QSystemTrayIcon

Rafał Zawadzki bluszcz at jabberpl.org
Thu Feb 21 12:03:29 GMT 2008


Thursday 21 February 2008 12:26:15 napisałeś(-łaś):
> 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.

After investigation - problem occurs only when showMessage is still visible.

BTW - I am using Qt 4.3.2.


> > * 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.

Yes, now it works,thanks (I am pasting working for someone else who will have 
same problem):

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
from PyQt4.QtCore import QTimer

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()"))
    tray.setToolTip("Ale czad!")
    def show_message():
        tray.showMessage("Title of the message", "Body of the message")
    QTimer.singleShot(100, show_message)
    sys.exit(app.exec_())


-- 
Rafał bluszcz Zawadzki 
http://my.jabberpl.org - use jabber
http://glam.pl - try secondhand clothes
http://bluszcz.net - my homepage
http://dkf.glam.pl - domorosły krytyk filmowy



More information about the PyQt mailing list