Python Forum
[PyQt] Hide Dock Icon for QSystemTrayIcon App
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] Hide Dock Icon for QSystemTrayIcon App
#1
I have a Qt program that uses a QSystemTrayIcon. Only the tray icon shows on Windows, but on Mac the generic Python Launcher icon also shows up in the dock. How do I hide this?

Although there are a couple StackExchange posts about this, none of them seem to work for me. I've tried doing something like this to no avail.

QMainWindow.setWindowFlags(QtCore.Qt.Tool)
I also found some stuff about AppKit, but couldn't figure out how to use the PyObjC package. Besides, it seems like it should be simpler.

For reference, here is the section of code which creates the tray icon. There are no other widgets or windows.

from PySide2.QtGui import QIcon
from PySide2.QtWidgets import QApplication, QAction, QMenu, QSystemTrayIcon,\
    QMessageBox
from pkg_resources import require, DistributionNotFound, resource_filename

def main():
    app = QApplication(sys.argv)
    app.setStyle("fusion")

    # Create the tray
    tray = QSystemTrayIcon(QIcon(resource_filename("application.server",
                                                   "res/bolt.png")))
    menu = QMenu()
    controls = []

    controls.append(QAction("About"))
    controls[-1].triggered.connect(about)
    menu.addAction(controls[-1])

    controls.append(QAction("Check Status"))
    controls[-1].triggered.connect(status)
    menu.addAction(controls[-1])

    menu.addSeparator()

    controls.append(QAction("Launch client"))
    controls[-1].triggered.connect(client)
    menu.addAction(controls[-1])

    controls.append(QAction("Stop Server"))
    controls[-1].triggered.connect(stop)
    menu.addAction(controls[-1])

    # Add the menu to the tray
    tray.setContextMenu(menu)
    tray.show()

    app.exec_()
Thank you!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Icon in tkinter menator01 8 669 May-03-2020, 02:01 PM
Last Post: wuf
  [Tkinter] Help setting text/title in dock/panel in tkinter gui FluxApex 2 1,093 Mar-18-2020, 07:15 PM
Last Post: FluxApex
  [Tkinter] Password Reveal Icon Evil_Patrick 2 810 Nov-29-2019, 02:20 PM
Last Post: Evil_Patrick
  [Tkinter] Window Icon Evil_Patrick 6 2,840 Oct-18-2019, 11:26 AM
Last Post: Evil_Patrick
  Button with Image Icon Friend 2 1,441 Jul-25-2019, 09:39 AM
Last Post: Friend
  General help with hide show status bar for a begineer in python ArakelTheDragon 0 744 Mar-17-2019, 11:58 AM
Last Post: ArakelTheDragon
  Hide button when clicked frequency 2 2,635 Dec-24-2018, 02:10 PM
Last Post: frequency
  [PyGUI] Hi All, how to hide/mask user input in PySimpleGUI nmrt 1 4,370 Sep-21-2018, 09:59 AM
Last Post: nmrt
  [PYQT5] Crashing when using .hide() and .show() aking76 0 3,453 Sep-18-2018, 02:09 PM
Last Post: aking76
  [Tkinter] How to show and hide tkinter entry box when select yes from drop down Prince_Bhatia 1 3,285 Jun-12-2018, 08:05 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020