从任务栏隐藏窗口 [英] Hide window from taskbar
问题描述
我正在尝试将托盘窗口最小化,但它似乎拒绝从任务栏隐藏.我花了一点时间将问题代码提炼为这个.这不是 mcuh,所以我想知道我是否需要其他东西来将我的应用程序隐藏到 Windows 7 的托盘中.
I'm trying to minimize a window to the tray, but it seems it refuses to hide from the taskbar. I've spent a little time and distilled the problem code down to this. It's not mcuh so I'm wondering if I need something else to hide my app to tray in Windows 7.
import sys, os
from PyQt4 import uic
from PyQt4.QtGui import QMainWindow, QApplication
class MyClass(QMainWindow):
def __init__(self, parent = None):
QMainWindow.__init__(self, parent)
self.ui = uic.loadUi(os.path.join("gui", "timeTrackerClientGUI.ui"), self)
def hideEvent(self, event):
self.hide()
def showEvent(self, event):
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
wnd = MyClass()
wnd.show()
app.exec_()
似乎应用程序图标确实隐藏了,但随后又弹出了另一个图标,如果我多次单击任务栏图标,我可以让这两个图标闪烁,在第一个隐藏之前的一瞬间看起来有点像这样:
It seems the application icon does hide but then another one pops up, If I click the taskbar icon multiple times I can get these two icons flickering, looks kind of like this for a splitsecond before the first one hides:
推荐答案
它需要一个相当丑陋的 hack 才能让它工作,但如果有人感兴趣,这里是最终代码,ph 是我的特定于平台的模块,你可以使用平台.取而代之的名称或类似函数:
It took a quite ugly hack to get it working but here's the final code if anybody is interested, ph is my platform-specific module, you can use platform.name or similar function instead:
def hideEvent(self, event):
self.hide()
if ph.is_windows():
self.hidden = True
self.setWindowFlags(Qt.ToolTip)
def showEvent(self, event):
if ph.is_windows() and self.hidden:
self.setWindowFlags(Qt.Window)
self.hidden = False
self.show()
这篇关于从任务栏隐藏窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!