我想在屏幕上隐藏应用,但不是从任务栏隐藏,我尝试了这个:
app = QtWidgets.QApplication([])
w = QtWidgets.QWidget()
w.show()
w.resize(0, 0)
但它不起作用,任何想法?
答案 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_())