Details
-
Bug
-
Resolution: Fixed
-
P2: Important
-
6.5.3
-
None
-
windows 11 22621.2361
Python 3.11.4
-
-
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
Issue Links
- relates to
-
QTBUG-74383 QSystemTrayIcon initially visible, hide() not working
- Reported
For Gerrit Dashboard: QTBUG-118133 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
512308,9 | Fix setting SysTrayIcon visible after explicitly hiding it | dev | qt/qtbase | Status: MERGED | +2 | 0 |
518298,2 | Fix setting SysTrayIcon visible after explicitly hiding it | 6.6 | qt/qtbase | Status: MERGED | +2 | 0 |
518381,2 | Fix setting SysTrayIcon visible after explicitly hiding it | tqtc/lts-6.5 | qt/tqtc-qtbase | Status: MERGED | +2 | 0 |
522910,2 | Fix setting SysTrayIcon visible after explicitly hiding it | tqtc/lts-6.2 | qt/tqtc-qtbase | Status: MERGED | +2 | 0 |