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. Draw digits in the QSystemTrayIcon
Forum Updated to NodeBB v4.3 + New Features

Draw digits in the QSystemTrayIcon

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 516 Views 3 Watching
  • 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.
  • G Offline
    G Offline
    giusdbg
    wrote on last edited by
    #1

    The previous object

    KSystemTray : public QLabel
    

    was derived from QLabel, so it was possible to draw digits in the trayicon.

    The new object

    KSystemTrayIcon : public QSystemTrayIcon
    
    QSystemTrayIcon : public QObject
    

    is derived from QObject.

    Does anyone have any idea how to draw digits in the new trayicon?

    SGaistS 1 Reply Last reply
    0
    • G giusdbg

      The previous object

      KSystemTray : public QLabel
      

      was derived from QLabel, so it was possible to draw digits in the trayicon.

      The new object

      KSystemTrayIcon : public QSystemTrayIcon
      
      QSystemTrayIcon : public QObject
      

      is derived from QObject.

      Does anyone have any idea how to draw digits in the new trayicon?

      SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      One possible way is to generate your own image, paint your numbers on it and then update the icon of your QSystemTrayIcon object.

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

      G 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        One possible way is to generate your own image, paint your numbers on it and then update the icon of your QSystemTrayIcon object.

        G Offline
        G Offline
        giusdbg
        wrote on last edited by giusdbg
        #3

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

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

          Based on your answer, I would guess you are working within a KDE environment, correct ?

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

          G 1 Reply Last reply
          0
          • SGaistS SGaist

            Based on your answer, I would guess you are working within a KDE environment, correct ?

            G Offline
            G Offline
            giusdbg
            wrote on last edited by
            #5

            @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).

            Screenshot_20230603_224520.png

            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();
            
            G 1 Reply Last reply
            0
            • G giusdbg

              @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).

              Screenshot_20230603_224520.png

              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();
              
              G Offline
              G Offline
              giusdbg
              wrote on last edited by giusdbg
              #6

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

              1 Reply Last reply
              0
              • G giusdbg has marked this topic as solved on

              • Login

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