0

I want to hide a window immediately after it is created. It works only if I do this with the help of button or something.

class Example(QWidget):
    def __init__(self, parent=None):
        super(Example, self).__init__(parent)
        self.hide() # doesn't work
        self.btn = QPushButton('Hide', self)
        self.btn.clicked.connect(self.click) # works
        self.btn.show()

    def click(self): # works
        self.hide()
Xantium
  • 11,201
  • 10
  • 62
  • 89
Joe Doe
  • 13
  • 2

2 Answers2

0

Apparently it seems that the code should work. What may be happening is that you are calling show() after creating the object. For example:

example = Example()
example.show()

Read this answer about hide() and show(): What's the difference in Qt between setVisible, setShown and show/hide

Ribes
  • 455
  • 2
  • 17
0

You can use QtCore.QTimer

class Example(QWidget):
    def __init__(self, app):
        QWidget.__init__(self)
        QTimer.singleShot(0, self.hide)
Liron Lavi
  • 421
  • 1
  • 5
  • 16