How to hide PyQt4 Python application taskbar icon?

I want to create a Windows desktop widget. I will create a user interface for the widget in Qt Designer and add functionality using Python. But I do not want the application to have a taskbar icon at all. How can I change my code and make my application (and its instances or other similar applications) not have a taskbar?

How can I hide the taskbar icon in windows? Here is a sample code:

import sys from PyQt4 import QtGui from PyQt4.uic import loadUiType Ui_MainWindow, QMainWindow = loadUiType('try.ui') class Main(QMainWindow, Ui_MainWindow): def __init__(self, ): super(Main, self).__init__() self.setupUi(self) if __name__ == '__main__': app = QtGui.QApplication(sys.argv) main = Main() main.show() sys.exit(app.exec_()) 

and this is his ui, "try.ui":

 <?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>Form</class> <widget class="QWidget" name="Form"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>211</width> <height>157</height> </rect> </property> <property name="windowTitle"> <string>Form</string> </property> <widget class="QPushButton" name="pushButton"> <property name="geometry"> <rect> <x>60</x> <y>60</y> <width>75</width> <height>23</height> </rect> </property> <property name="text"> <string>PushButton</string> </property> </widget> </widget> <resources/> <connections/> </ui> 

Edit: This shows how the default icon looks in the taskbar. I just do not want it there, as expected from the widget.

+5
source share
2 answers

Try the following:

 from PyQt4 import QtCore ... class Main(QMainWindow, Ui_MainWindow): def __init__(self, ): super(Main, self).__init__() self.setWindowFlags(QtCore.Qt.Tool) #This 
+3
source

I think this may be the problem:

In Windows 7, the taskbar is not intended for “application Windows” as such, it is for “User Application Models”. For example, if you have slightly different instances of your application, and each instance has its own icon, then all of them will be grouped under the same icon taskbar. Windows uses various heuristics to determine whether instances should be grouped or not, in which case he decided that everything that was placed by Pythonw.exe should be grouped under the icon for Pythonw.exe.

The correct solution for Pythonw.exe is to tell Windows that it is just hosting other applications. Perhaps a future release of Python will do this. Alternatively, you can add a registry key to tell Windows that Pythonw.exe is just a host, not an application in its own right. See the MSDN documentation for AppUserModelID.

Alternatively, you can use the Windows call from Python to explicitly tell Windows which AppUserModelID is correct for this process:

 import ctypes myappid = 'mycompany.myproduct.subproduct.version' # arbitrary string ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid) 
0
source

All Articles