从屏幕而不是任务栏隐藏应用程序

Hide the app from screen but not from taskbar

我想从屏幕而不是任务栏隐藏应用程序,我试过这个:

app = QtWidgets.QApplication([])
w = QtWidgets.QWidget()
w.show()
w.resize(0, 0)

但它不起作用,知道吗?

app = QtWidgets.QApplication([])
w = QtWidgets.QWidget()
w.showMinimized()

我使用 QMainWindow 而不是 QWidget,然后我覆盖 focusInEventfocusOutEvent 个事件。

#!/usr/bin/python3
# -*- coding: utf-8 -*-

from PyQt5.QtWidgets import QMainWindow, QApplication
from PyQt5.QtCore import Qt
from sys import argv, exit

class Window(QMainWindow):
    def __init__(self):
        super(Window, self).__init__()
        self.setFocusPolicy(Qt.StrongFocus)

    def focusInEvent(self, event):
        print('focusInEvent')
        self.setWindowTitle('focusInEvent')
        self.showMinimized()

    def focusOutEvent(self, event):
        print('focusOutEvent')
        self.setWindowTitle('focusOutEvent')
#        self.showMinimized()

if __name__ == '__main__':
    app = QApplication([])
    w = Window()
    w.showMinimized()
    exit(app.exec_())