Hide the app from screen but not from taskbar

允我心安 提交于 2019-12-12 00:39:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!