PDA

View Full Version : dynamic systray icon



mattie
2nd April 2010, 20:44
Hi,

I am trying to paint a systray icon on the fly. My concrete case: I want to reflect the progress of something in the systray icon by drawing a piechart. I could draw into an QImage and set the icon again everytime I update the qimage. However, this does not seem a nice way?
So I tried subclassing QIcon, overriding the paint method and setting that icon for the systray. However, the paint method is never called (probably because the paint method is not virtual?).
Then I looked into the QIconEngine stuff, but I am doubtful I am going the right way..

What would be the correct way to paint an custom/dynamic systemtray icon?

thanks
matthias

aamer4yu
2nd April 2010, 21:30
However, the paint method is never called (probably because the paint method is not virtual?).
Not probably, but surely there is no paintEvent for a QIcon class !! It isnt derived from QWidget !

I could draw into an QImage and set the icon again everytime I update the qimage. However, this does not seem a nice way?
Another way doesnt come to my mind. QSystemTrayIcon is also derived from QObject, so am not sure how the actual painting is done. May be it system dependant.
Looking into the source code of QSYstrayICon ,,,may be that will give you a hint

mattie
6th April 2010, 18:01
Not probably, but surely there is no paintEvent for a QIcon class !! It isnt derived from QWidget !
no, I said "paint" method :)

I had looked at QIconEngineV2 but was confused as I didn't see any paint method and QIconEngine is deprecated. Now I realized it is a subclass of QIconEngine, so now it all starts to make sense ;)

suseway
10th December 2010, 13:36
Can tell me how did you do this? example code?

mattie
10th December 2010, 14:29
in the end I just folded :)
there does not seem to be a better way (and when you think about it, it makes sense) and since I update the systray only every 60secs anyway, I accepted the overhead :)

I did find out that on windows you could send a NIM_MODIFY event using the Shell_NotifyIcon fuction but that requires you to update the HICON anyway. No idea how it works on linux though.

suseway
10th December 2010, 21:43
So can you post the code for Linux?

suseway
13th December 2010, 06:21
Mattie: sorry, can you post the full code?