问题
I would like to hide the app from screen but not from taskbar, I tried this:
app = QtWidgets.QApplication([])
w = QtWidgets.QWidget()
w.show()
w.resize(0, 0)
but it doesn't work, any idea?
回答1:
app = QtWidgets.QApplication([])
w = QtWidgets.QWidget()
w.showMinimized()
回答2:
I use QMainWindow instead of QWidget, then I override the focusInEvent and focusOutEvent events.
#!/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_())
来源:https://stackoverflow.com/questions/41544941/hide-the-app-from-screen-but-not-from-taskbar