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 cannot respond to middle click on win11
Forum Updated to NodeBB v4.3 + New Features

QSystemTrayIcon cannot respond to middle click on win11

Scheduled Pinned Locked Moved Unsolved Qt for Python
6 Posts 2 Posters 810 Views 2 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.
  • A Offline
    A Offline
    auryouth
    wrote on last edited by
    #1
    import sys
    
    from PySide6.QtGui import QIcon
    from PySide6.QtWidgets import QApplication, QSystemTrayIcon
    
    
    class sysTray(QSystemTrayIcon):
        def __init__(self, parent=None):
            super().__init__(parent)
            self.icon = QIcon("Meta.ico")
            self.setIcon(self.icon)
            self.activated.connect(self.on_tray_activated)
            self.show()
    
        def on_tray_activated(self, reason):
            print(reason)
    
    
    if __name__ == "__main__":
        app = QApplication(sys.argv)
        tray = sysTray()
        sys.exit(app.exec())
    

    This is a simple example to create a system tray in windows with PySide6. However, when I middle click the tray, it outputs ActivationReason.Trigger rather than ActivationReason.MiddleClick. Is there something I am missing or is this a problem in windows11?

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

      Hi and welcome to devnet,

      Might be a silly question but are you sure your middle button is identified as such ?

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

      A 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi and welcome to devnet,

        Might be a silly question but are you sure your middle button is identified as such ?

        A Offline
        A Offline
        auryouth
        wrote on last edited by
        #3

        @SGaist
        Yes, I am sure.
        The result is as shown in the image below.

        freecompress-图片2.png

        SGaistS 1 Reply Last reply
        0
        • A auryouth

          @SGaist
          Yes, I am sure.
          The result is as shown in the image below.

          freecompress-图片2.png

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

          @auryouth I meant system wise.

          I would add an event filter to check how the mouse buttons are seen there to determine why Trigger is returned rather than MiddleClicked.

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

          A 1 Reply Last reply
          0
          • SGaistS SGaist

            @auryouth I meant system wise.

            I would add an event filter to check how the mouse buttons are seen there to determine why Trigger is returned rather than MiddleClicked.

            A Offline
            A Offline
            auryouth
            wrote on last edited by
            #5

            @SGaist
            I add en eventfilter to sysTray itself:

            import sys
            
            from PySide6.QtCore import QEvent, QObject
            from PySide6.QtGui import QAction, QIcon
            from PySide6.QtWidgets import QApplication, QMenu, QSystemTrayIcon
            
            
            class sysTray(QSystemTrayIcon):
                def __init__(self, parent=None):
                    super().__init__(parent)
            
                    self.installEventFilter(self)
            
                    self.icon = QIcon("icon/meta_running.ico")
                    self.setIcon(self.icon)
            
                    self._toggle_action = QAction("toggle", self)
                    self._tray_icon_menu = QMenu()
                    self._tray_icon_menu.addAction(self._toggle_action)
                    self.setContextMenu(self._tray_icon_menu)
            
                    self.show()
            
                def eventFilter(self, watched: QObject, event: QEvent) -> bool:
                    print(watched, event)
                    return super().eventFilter(watched, event)
            
            
            if __name__ == "__main__":
                app = QApplication(sys.argv)
                tray = sysTray()
                sys.exit(app.exec())
            

            When I click the tray it outputs nothing.
            And when I right click and move mouse to the context menu it outputs something.

            <__main__.sysTray(0x2a07487c970) at 0x000002A075151380> <PySide6.QtCore.QEvent(QEvent::ChildAdded)>
            <__main__.sysTray(0x2a07487c970) at 0x000002A075151380> <PySide6.QtCore.QEvent(QEvent::StatusTip)>
            

            I have tried QWidget and everything is OK in Windows 11. I have also tried QSystemTrayIcon in Arch Linux and it is also OK.

            No idea what is wrong with it in Windows 11.

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

              Can you try forcing the style of the application to windowsvista or fusion ?

              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