Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. QSystemTrayIcon doesn't show messages
Qt 6.11 is out! See what's new in the release blog

QSystemTrayIcon doesn't show messages

Scheduled Pinned Locked Moved Solved Qt for Python
9 Posts 4 Posters 2.7k Views 1 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.
  • superagaS Offline
    superagaS Offline
    superaga
    wrote on last edited by
    #1

    Hi all,

    I can make the systray icon appear in the systraybar (Win 10) with its menu.
    I can trigger actions from the menu, but I can't see any notification using the showMessage method.

    I made a small example to show the issue I'm having:

    import sys
    from typing import Dict
    from PyQt6.QtWidgets import QApplication, QSystemTrayIcon, QStyle, QMenu
    from PyQt6.QtCore import QObject, pyqtSignal, QTimer
    from PyQt6.QtGui import QIcon, QAction
    
    
    class SysTray(QObject):
        def __init__(self, app: QApplication) -> None:
            super().__init__(parent=None)
    
            self.systray = QSystemTrayIcon()
            if not self.systray.isSystemTrayAvailable():
                print("System tray not available for this system")
                return
    
            icon = QIcon("icon_system.png")
            self.systray.setIcon(icon)
            self.systray.setVisible(True)
            self.systray.setToolTip("My running systray example")
            self.timer = QTimer()
    
            self._make_menu()
            self.systray.setContextMenu(self.menu)
    
        def _make_menu(self) -> None:
            self.menu = QMenu()
            self.tmr_single = QAction("Trigger one shot timer")
            self.tmr_periodic = QAction("Trigger periodic timer")
            self.tmr_stop = QAction("Stop timer")
            self.item_quit = QAction("Quit")
    
            self.menu.addAction(self.tmr_single)
            self.menu.addAction(self.tmr_periodic)
            self.menu.addAction(self.tmr_stop)
            self.menu.addAction(self.item_quit)
    
        def timer_single(self) -> None:
            self.timer.setSingleShot(True)
            self.timer.timeout.connect(self.msg_timer_single)
            self.timer.start(3000)
    
        def msg_timer_single(self) -> None:
            msg = {
                "title": "Single shot timer", 
                "txt": "3 seconds elapsed", 
                "icon": "info"}
            print("Single timer finished")
            self.show_msg(msg)
    
        def timer_periodic(self) -> None:
            self.timer.setSingleShot(False)
            self.timer.timeout.connect(self.msg_timer_periodic)
            self.timer.start(3000)
    
        def msg_timer_periodic(self) -> None:
            msg = {
                "title": "Periodic shot timer",
                "txt": "3 seconds elapsed",
                "icon": "warn",
            }
            print("Periodic timer finished")
            self.show_msg(msg)
    
        def timer_stop(self) -> None:
            self.timer.stop()
    
        def show_msg(self, msg: Dict) -> None:
            _icon = None
            if msg["icon"] == "info":
                _icon = QSystemTrayIcon.MessageIcon.Information
            elif msg["icon"] == "warn":
                _icon = QSystemTrayIcon.MessageIcon.Warning
            elif msg["icon"] == "error":
                _icon = QSystemTrayIcon.MessageIcon.Critical
            else:
                _icon = QSystemTrayIcon.MessageIcon.NoIcon
            self.systray.showMessage(msg["title"], msg["txt"], _icon, 1000)
    
    
    def main():
        app = QApplication(sys.argv)
        systray = SysTray(app=app)
        systray.item_quit.triggered.connect(app.quit)
        systray.tmr_single.triggered.connect(systray.timer_single)
        systray.tmr_periodic.triggered.connect(systray.timer_periodic)
        systray.tmr_stop.triggered.connect(systray.timer_stop)
        sys.exit(app.exec())
    
    
    if __name__ == "__main__":
        main()
    

    This is the icon I used for the code, but you can of course use whatever you want.
    icon_system.png

    I really hope that the issue would be in the code and doesn't belong to my system policies (where I'm employed) which it would make the problem then irresolvable šŸ¤¦ā€ā™‚ļø.

    Any help would be super appreciated!
    šŸ™
    AGA

    1 Reply Last reply
    1
    • superagaS Offline
      superagaS Offline
      superaga
      wrote on last edited by
      #5

      I've been able to test my code on a home Win 10 PC and it works.
      So the problem it is related to my company policies.
      Many thanks to all for the support!
      šŸ˜‰

      systray_demo.png

      1 Reply Last reply
      1
      • superagaS Offline
        superagaS Offline
        superaga
        wrote on last edited by
        #2

        Anyone that could at least test the code and give me a feedback?
        It would be super appreciated!

        1 Reply Last reply
        0
        • CristianMaureiraC Offline
          CristianMaureiraC Offline
          CristianMaureira
          wrote on last edited by
          #3

          I don't have a Windows 10 at hand, but at least on Linux and Windows 11 I can see the Periodic timer message being showed every 3 seconds.
          (2024-05-14-181700_3840x2160_scrot.png

          It might be a Windows 10 issue, but I'd check if there are some related bugs.

          1 Reply Last reply
          1
          • superagaS Offline
            superagaS Offline
            superaga
            wrote on last edited by
            #4

            Many thanks for this!
            At least I know that the code works as expected.
            I'll aks to IT if there are some restrictions or setting I'm not aware of.

            1 Reply Last reply
            0
            • superagaS Offline
              superagaS Offline
              superaga
              wrote on last edited by
              #5

              I've been able to test my code on a home Win 10 PC and it works.
              So the problem it is related to my company policies.
              Many thanks to all for the support!
              šŸ˜‰

              systray_demo.png

              1 Reply Last reply
              1
              • superagaS superaga has marked this topic as solved on
              • superagaS Offline
                superagaS Offline
                superaga
                wrote on last edited by
                #6

                Hi all,
                I'd like to change the "message title" that appears in the picture as Python.

                2a46d655-7fc0-4d5b-b760-c93397646ba1-image.png

                On the documentation page I couldn't find any method/properties related to that other then:

                • title: See bold text in the image.
                • message: See normal text in the message.
                • icon: I can also decide which icon use.

                Any idea?
                Super thanks!
                AGA

                jsulmJ 1 Reply Last reply
                0
                • superagaS superaga

                  Hi all,
                  I'd like to change the "message title" that appears in the picture as Python.

                  2a46d655-7fc0-4d5b-b760-c93397646ba1-image.png

                  On the documentation page I couldn't find any method/properties related to that other then:

                  • title: See bold text in the image.
                  • message: See normal text in the message.
                  • icon: I can also decide which icon use.

                  Any idea?
                  Super thanks!
                  AGA

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #7

                  @superaga said in QSystemTrayIcon doesn't show messages:

                  I'd like to change the "message title"

                  I think it is the title of your application, try to change that

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  superagaS 1 Reply Last reply
                  0
                  • jsulmJ jsulm

                    @superaga said in QSystemTrayIcon doesn't show messages:

                    I'd like to change the "message title"

                    I think it is the title of your application, try to change that

                    superagaS Offline
                    superagaS Offline
                    superaga
                    wrote on last edited by
                    #8

                    @jsulm said in QSystemTrayIcon doesn't show messages:

                    I think it is the title of your application, try to change that

                    Hi @jsulm, many thanks for your reply.
                    I just tried both: QApplication.setApplicationDisplayName and QApplication.setApplicationName, but do not work.

                    Any other idea?
                    Cheers

                    1 Reply Last reply
                    0
                    • L Offline
                      L Offline
                      LuoMeng
                      wrote on last edited by
                      #9
                      This post is deleted!
                      1 Reply Last reply
                      0
                      • L LuoMeng referenced this topic on

                      • Login

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