从屏幕隐藏应用程序,但不从任务栏隐藏

时间:2017-01-09 09:40:24

标签: python pyqt5 taskbar

我想在屏幕上隐藏应用,但不是从任务栏隐藏,我尝试了这个:

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

但它不起作用,任何想法?

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

我使用 QMainWindow 代替 QWidget ,然后我覆盖 focusInEvent focusOutEvent 事件。

#!/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_())