Draw digits in the QSystemTrayIcon
-
The previous object
KSystemTray : public QLabelwas derived from QLabel, so it was possible to draw digits in the trayicon.
The new object
KSystemTrayIcon : public QSystemTrayIcon QSystemTrayIcon : public QObjectis derived from QObject.
Does anyone have any idea how to draw digits in the new trayicon?
-
The previous object
KSystemTray : public QLabelwas derived from QLabel, so it was possible to draw digits in the trayicon.
The new object
KSystemTrayIcon : public QSystemTrayIcon QSystemTrayIcon : public QObjectis derived from QObject.
Does anyone have any idea how to draw digits in the new trayicon?
Hi,
One possible way is to generate your own image, paint your numbers on it and then update the icon of your QSystemTrayIcon object.
-
Hi,
One possible way is to generate your own image, paint your numbers on it and then update the icon of your QSystemTrayIcon object.
@SGaist Hi.
Yes, thank you, so I should also be able to recover the original code that draws on the trayicon,int w= geometry().width(); int h= geometry().height(); QPixmap pixmap(24,24); pixmap.fill(Qt::white); QPainter painter(&pixmap); QColor color= sensor->getAlarm() ? colorAlarm : colorNormal; QColor colorShadow= color.dark(200); painter.setPen(color); painter.drawLine(2, 2 , w-2,2 ); painter.drawLine(2, h-3, w-2,h-3); painter.setPen(colorShadow); .......................For a change, I discovered that I have a bigger problem above this, this port is never a single problem, but a nest of wasps, a matryoshka of problems 😧 😤 😅 ,
i can't set the icon I want in the trayicon, it always activates the application icon, and currently I have no idea why this happens.
Update,
If I completely remove the application file icon (of the various versions, from the cache, etc.), then I can set a test icon.There is something resetting the application icon.
-
Based on your answer, I would guess you are working within a KDE environment, correct ?
-
@SGaist Yes, fedora 38 kde (kde4 libraries).
The problem seems to be in the QSystemTrayIcon object.
It may be an kde integration problem or in the no longer maintained kde4 libraries.However, after having burned a lot of hours, I decided for the umpteenth regression.
I removed K-QSystemTrayIcon object, and inserted KStatusNotifierItem object (it's not friendly, but it's much more consistent).
Now I have to re-insert the context menus again and then try everything again.
And then I can't get the program icon to show anymore (and I have no idea why).But at least now I have the sensors in the trayicon (see icon with white background).

LMSensorDockPanel::LMSensorDockPanel(Sensor *newSensor, QMenu *menu, const char *name) : KStatusNotifierItem ( name, newSensor ) /* : KSystemTrayIcon() */ ......................... setIconByName( qsDockImage ); setToolTipIconByName( kadAboutData->programName() ); ......................... QPixmap pixmap(32,32); pixmap.fill(); QPainter painter(&pixmap); QColor color= sensor->getAlarm() ? colorAlarm : colorNormal; QColor colorShadow= color.dark(200); painter.setPen(color); painter.drawLine(2, 2 , w-2,2 ); painter.drawLine(2, h-3, w-2,h-3); painter.setPen(colorShadow); .......................... setIconByPixmap( pixmap ); QPixmapCache::clear(); -
@SGaist Yes, fedora 38 kde (kde4 libraries).
The problem seems to be in the QSystemTrayIcon object.
It may be an kde integration problem or in the no longer maintained kde4 libraries.However, after having burned a lot of hours, I decided for the umpteenth regression.
I removed K-QSystemTrayIcon object, and inserted KStatusNotifierItem object (it's not friendly, but it's much more consistent).
Now I have to re-insert the context menus again and then try everything again.
And then I can't get the program icon to show anymore (and I have no idea why).But at least now I have the sensors in the trayicon (see icon with white background).

LMSensorDockPanel::LMSensorDockPanel(Sensor *newSensor, QMenu *menu, const char *name) : KStatusNotifierItem ( name, newSensor ) /* : KSystemTrayIcon() */ ......................... setIconByName( qsDockImage ); setToolTipIconByName( kadAboutData->programName() ); ......................... QPixmap pixmap(32,32); pixmap.fill(); QPainter painter(&pixmap); QColor color= sensor->getAlarm() ? colorAlarm : colorNormal; QColor colorShadow= color.dark(200); painter.setPen(color); painter.drawLine(2, 2 , w-2,2 ); painter.drawLine(2, h-3, w-2,h-3); painter.setPen(colorShadow); .......................... setIconByPixmap( pixmap ); QPixmapCache::clear();@SGaist Now also the drawing of the traybar icon works well.
Thank you.
P.S. KStatusNotifierItem is a good object (uses dbus).
Probably I use it also badly, it seems to me that it also provides the icon overlay.PP.SS. Working on this thing brought up various issues that I fixed, events no longer spawning, wrong object destructions, etc. .
In the end, a lot in the end 😅 , it was a good thing, it was a jump from 80% to 99% of things functioning 🔮 .
As a big deal I think I have only occasional crashes left, probably timers that don't start and stop correctly. -
G giusdbg has marked this topic as solved on