[solved] PyQt4 + PIL + SystemTrayIcon issue



  • I was having some fun with this to make a simple cpu temperature display.
    @ msg = "61"
    iconPIL = Image.new("RGB", (22,22), "black")
    draw = ImageDraw.Draw(iconPIL)
    fontSize = 22
    font = ImageFont.truetype("fontLocationBlablabla", fontSize)
    draw.text( ((22-w)/2, 0), msg, fill="red", font=font)
    del draw

    #convert to pixmap
    imgQt = ImageQt.ImageQt(iconPIL)
    imgPix = QtGui.QPixmap.fromImage(imgQt)    
    #imgPix.save("/location/" + msg, "png")
    
    #... and then I just set the icon to QSystemTrayIcon
    
    setIcon(QtGui.QIcon(imgPix))
    

    @

    the problem is that sometimes ( I'd say 30% ) my icon gets corrupted or something like that
    !http://i.imgur.com/daJ9Ojr.png(issue)!
    as you can see on the image above there's 2 images
    on the left of the "bell" icon we got a "61" image just fine
    and on the right of the "bell" icon we got our bugged image o.O

    it seems to work just fine if I save the image as png first, and create the QIcon from that tough o.OOOO!!!
    any ideas why?

    Edit: well it was a problem with ImageQt.ImageQt, nvm
    I was losing the image reference and python was using the same memory position for other things I guess. So I just had to save that image to a var, my bad.


  • Lifetime Qt Champion

    Hi and welcome to devnet !

    Glad you found out and thanks for sharing.

    Can you also please update the thread title prepending [solved] so other forum users may know a solution has been found :)



  • Yeh, was looking if there was an automated way.


  • Lifetime Qt Champion

    Not yet no, but maybe in the future :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.