Hide the app from screen but not from taskbar

207 views Asked by At

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?

2

There are 2 answers

2
ZiTAL On BEST ANSWER

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_())
1
a_manthey_67 On
app = QtWidgets.QApplication([])
w = QtWidgets.QWidget()
w.showMinimized()