如何隐藏 PyQt4 Python 应用程序的任务栏图标?
How to hide taskbar icon of a PyQt4 Python application?
我想创建一个 windows 桌面小部件。我将在 Qt Designer 中为小部件创建自定义 UI,并使用 Python 添加功能。但是,我根本不希望应用程序在任务栏上有图标。我应该如何修改我的代码并使我的应用程序(及其实例或其他类似应用程序)没有任务栏足迹?
如何隐藏 windows 上的任务栏图标?这是一个示例代码:
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_())
这是它的 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>
编辑:Here 是任务栏上默认图标的样子。正如小部件所期望的那样,我只是不想在那里。
我认为 this 可能是问题所在:
In Windows 7, the taskbar is not for "Application Windows" per se,
it's for "Application User Models". For example, if you have several
different instances of your application running, and each instance has
its own icon, then they will all be grouped under a single taskbar
icon. Windows uses various heuristics to decide whether different
instances should be grouped or not, and in this case it decided that
everything hosted by Pythonw.exe should be grouped under the icon for
Pythonw.exe.
The correct solution is for Pythonw.exe to tell Windows that it is
merely 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 rather than an application in
its own right. See MSDN documentation for AppUserModelIDs.
Alternatively, you can use a Windows call from Python, to explicitly
tell Windows what the correct AppUserModelID is for this process:
import ctypes myappid = 'mycompany.myproduct.subproduct.version' #
arbitrary string
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
试试这个:
from PyQt4 import QtCore
...
class Main(QMainWindow, Ui_MainWindow):
def __init__(self, ):
super(Main, self).__init__()
self.setWindowFlags(QtCore.Qt.Tool) #This
我想创建一个 windows 桌面小部件。我将在 Qt Designer 中为小部件创建自定义 UI,并使用 Python 添加功能。但是,我根本不希望应用程序在任务栏上有图标。我应该如何修改我的代码并使我的应用程序(及其实例或其他类似应用程序)没有任务栏足迹?
如何隐藏 windows 上的任务栏图标?这是一个示例代码:
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_())
这是它的 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>
编辑:Here 是任务栏上默认图标的样子。正如小部件所期望的那样,我只是不想在那里。
我认为 this 可能是问题所在:
In Windows 7, the taskbar is not for "Application Windows" per se, it's for "Application User Models". For example, if you have several different instances of your application running, and each instance has its own icon, then they will all be grouped under a single taskbar icon. Windows uses various heuristics to decide whether different instances should be grouped or not, and in this case it decided that everything hosted by Pythonw.exe should be grouped under the icon for Pythonw.exe.
The correct solution is for Pythonw.exe to tell Windows that it is merely 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 rather than an application in its own right. See MSDN documentation for AppUserModelIDs.
Alternatively, you can use a Windows call from Python, to explicitly tell Windows what the correct AppUserModelID is for this process:
import ctypes myappid = 'mycompany.myproduct.subproduct.version' #
arbitrary string
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
试试这个:
from PyQt4 import QtCore
...
class Main(QMainWindow, Ui_MainWindow):
def __init__(self, ):
super(Main, self).__init__()
self.setWindowFlags(QtCore.Qt.Tool) #This