Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved] PyQt4 + PIL + SystemTrayIcon issue
QtWS25 Last Chance

[solved] PyQt4 + PIL + SystemTrayIcon issue

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hugo00
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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 :)

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hugo00
        wrote on last edited by
        #3

        Yeh, was looking if there was an automated way.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Not yet no, but maybe in the future :)

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved