Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-118133

Windows QPA: QSystemIconTrayIcon::show() not working after calling hide()

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2: Important
    • 6.5.4, 6.2.12, 6.6.1, 6.7.0 FF
    • 6.5.3
    • QPA: Windows
    • None
    • windows 11 22621.2361
      Python 3.11.4
    • Windows
    • 77e0e7c41 (dev), 72331b450 (6.6), 7b54a89d5 (tqtc/lts-6.5), a4ea45033 (tqtc/lts-6.2)

    Description

      Steps to reproduce:

      • Apply qtbug118133_repro.diff to systray example. It cyclically toggles visibility of the tray
      • Expected: Icon hides and shows
      • Actual: Icon disappears and does not show again

      My app needs to dynamically show or hide system tray. But once I call {{`.hide()` }}function on it, and then call{{ `.show()` }}on it, it does not show up.

      I've created a minimal reproducible code to show what issue is happening with{{ `QSystemTrayIcon` }}class of PySide6.

      import os
      import sys
      from PySide6.QtWidgets import *
      from PySide6.QtCore import *
      from PySide6.QtGui import *
      import resources_rc
      
      app = QApplication(sys.argv)
      
      # Images
      def _image(name: str):
          return os.path.join(':', 'saved_files', 'images', f'{name}.png')
      
      # Setup system tray
      tray = QSystemTrayIcon(QIcon(_image('folder')))
      tray.show()
      print('> Running\n')
      def toggle_tray():
          tray.setVisible(not tray.isVisible())
          print(f'[State Toggled] Tray Visible = {tray.isVisible()}')
      
      # Timer object
      timer = QTimer()
      timer.timeout.connect(toggle_tray)
      timer.start(3000)
          
      app.exec() 

      I created above minimal reproducible code to diagnose the issue but was unsuccessful.

      1. How it should work (reproducible code): 
      It should show system tray icon and then after 3 seconds, hide. Then after 3 seconds, show. Then after 3 seconds, hide. And cycle continues....

      2. How it's behaving:
      It shows up perfectly on start (as it should), and then after 3 seconds it hides (as it should), but after next 3 seconds, IT DOESN'T SHOW UP (as it should have).

      3. Workaround I found (after many trials and errors): 
      If I set icon for system tray using `tray.setIcon(QIcon(_image('folder')))` in `toggle_tray()`, it works as intended, but that's just a workaround. I don't understand why the original code is not working. Is it because `.setVisible(False)` is removing the icon from `QSystemTrayIcon()` or is it something else? I really need your help regarding this.

       

      Attachments

        1. image-2023-12-03-13-03-32-944.png
          image-2023-12-03-13-03-32-944.png
          23 kB
        2. image-2024-01-16-11-12-08-447.png
          image-2024-01-16-11-12-08-447.png
          137 kB
        3. image-2024-01-16-11-14-10-531.png
          image-2024-01-16-11-14-10-531.png
          77 kB
        4. pyside2489.py
          0.9 kB
        5. QTBUG_118133.cpp
          0.6 kB
        6. qtbug118133_repro.diff
          2 kB

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              owolff Oliver Wolff
              ectoruseff Ecto Ruseff
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes