I'm a beginner in PyQt. I was trying to create a simple app to try some of the toolkit's many features. My question is, how can I hide the app icon from the taskbar? I don't want the user to be able to see the icon in taskbar and to minimize it using this icon. Is there any window flags that I can use to achieve this?
-
possible duplicate of [PyQt4 Minimize to Tray](http://stackoverflow.com/questions/758256/pyqt4-minimize-to-tray) – Katriel Oct 28 '10 at 16:52
-
1@katrielalex: I think he means the taskbar icon and not the tray icon. – user225312 Oct 28 '10 at 17:03
-
1@PulpFiction: yes; the way you "minimise to tray" is to hide the taskbar icon and make a tray icon. – Katriel Oct 28 '10 at 19:39
-
@katrielalex Yes, I meant hiding the taskbar icon, while the app is still not minimized. – eternalthinker Oct 29 '10 at 04:32
7 Answers
This drove me nuts for days. Complete app code to implement below.
Key bits:
- override closeEvent(), enabling it to do either of just hiding window or true exit
- create some facility for user to choose either hide or exit behavior
- don't show() main window on instantiation, just exec_() the App
import sys from PyQt4.QtGui import QAction, QApplication, QFrame, QIcon, \ QMainWindow, QMenu, QSystemTrayIcon from PyQt4.QtCore import SIGNAL class MyApp(QMainWindow): def __init__(self, parent, title): super(QMainWindow, self).__init__(parent) self.exitOnClose = False exit = QAction(QIcon(), "Exit", self) self.connect(exit, SIGNAL("triggered()"), self.exitEvent) self.trayIcon = QSystemTrayIcon(QIcon(), self) menu = QMenu(self) menu.addAction(exit) self.trayIcon.setContextMenu(menu) self.connect(self.trayIcon, \ SIGNAL("activated(QSystemTrayIcon::ActivationReason)"), \ self.trayIconActivated) self.trayIcon.show() self.trayIcon.showMessage("MyApp is running!", "Click to open window\nRight click for menu" ) def trayIconActivated(self, reason): if reason == QSystemTrayIcon.Context: self.trayIcon.contextMenu().show() elif reason == QSystemTrayIcon.Trigger: self.show() self.raise_() def closeEvent(self, event): if self.exitOnClose: self.trayIcon.hide() del self.trayIcon event.accept() else: self.hide() event.setAccepted(True) event.ignore() def exitEvent(self): self.exitOnClose = True self.close() if __name__ == "__main__": app = QApplication(sys.argv) myapp = MyApp(None, "My System Tray App") app.exec_()
Adapted from this thread:
import sys
from PyQt4.QtGui import *
if __name__ == '__main__':
app = QApplication(sys.argv)
widget = QWidget()
mainWindow = QMainWindow(widget)
mainWindow.show()
sys.exit(app.exec_())

- 893
- 11
- 24
If you are on Ubuntu with Unity and want to hide an application's icon from the launcher on the left-hand-side, you will probably need Qt.SplashScreen
. This worked for me but I don't remember if I also needed Qt.Tool
, which is enough on Windows. For the SplashScreen attempt you may have to reimplement the resize functionality as it disables this feature of a QStatusBar (that has a SizeGrip) for example.
Here is a little example to try out window flags.

- 4,350
- 9
- 47
- 87
I wouldn't recommend trying to hide an application's taskbar presence, especially if the application is visible. If you are only trying to prevent minimizing from the taskbar then you can achieve this by creating your top level widget with the following window flags like this:
QWidget *mainWindow = new QWidget(0, Qt::CustomizeWindowHint
| Qt::WindowTitleHint | Qt::WindowSystemMenuHint
| Qt::WindowCloseButtonHint | Qt::WindowMaximizeButtonHint);
If you don't want a maximize flag, you can leave that one out of the list too.
The various window flags that Qt can use are documented here (Qt::WindowFlags).

- 21,942
- 7
- 74
- 67
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5 import QtCore
import sys
class Window(QMainWindow):
def __init__(self):
super().__init__()
# this will hide the app from task bar
self.setWindowFlag(QtCore.Qt.Tool)
self.setGeometry(60, 60, 800, 500)
# creating a label widget
# by default label will display at top left corner
self.label_1 = QLabel('no task bar', self)
# moving position
self.label_1.move(100, 100)
# show all the widgets
self.show()