title: PySide Child Window
body: <p>I want to open a child window in the <code>MainWindow</code> of my app. I want to disallow the user to interact with the parent window, and only allow him to open that child window once. For example, the 'About' window in many applications.</p>
  
  <pre><code>class Ui_AboutDialog(object):
      def setupUi(self, MainWindow):
          MainWindow.setObjectName("MainWindow")
          MainWindow.resize(500, 300)
          MainWindow.setMinimumSize(QtCore.QSize(500, 300))
          MainWindow.setMaximumSize(QtCore.QSize(500, 300))
          MainWindow.setLocale(QtCore.QLocale(QtCore.QLocale.English, QtCore.QLocale.UnitedStates))
          self.centralwidget = QtGui.QWidget(MainWindow)
          self.centralwidget.setLocale(QtCore.QLocale(QtCore.QLocale.English, QtCore.QLocale.UnitedStates))
          self.centralwidget.setObjectName("centralwidget")
          self.label = QtGui.QLabel(self.centralwidget)
          self.label.setGeometry(QtCore.QRect(10, 10, 481, 181))
          self.label.setObjectName("label")
          #MainWindow.setCentralWidget(self.centralwidget)
  
          self.retranslateUi(MainWindow)
  </code></pre>
  
  <p>Here is how I call it in the <code>MainWindow</code>:</p>
  
  <pre><code>class Ui_MainWindow(object):
      def setupUi(self, MainWindow):
          ...
          ...
          self.actionAbout.triggered.connect(lambda: self.openAbout(MainWindow))
  
      def openAbout(self, MainWindow):
          aboutDialog = QtGui.QDialog(MainWindow)
          aboutUi = Ui_AboutDialog()
          aboutUi.setupUi(aboutDialog)
          aboutDialog.show()
  
         ...
         ...
  </code></pre>
  
  <hr>
  
  <h2>Solution</h2>
  
  <pre><code>def openAbout(self, MainWindow):
      if self.AboutDialog is None:
          self.AboutDialog = QtGui.QDialog(MainWindow)
          aboutUi = Ui_AboutDialog()
          aboutUi.setupUi(self.AboutDialog)
      self.AboutDialog.setModal(True)
      self.AboutDialog.show()
  </code></pre>
  
  <p><code>self.AboutDialog</code> is set to <code>None</code> in <code>setupUi</code> of <code>class Ui_MainWindow</code>.</p>
  
  <p>I think while using <code>self.AboutDialog.setModal(True)</code> we may go without <code>self.AboutDialog</code> as follows:</p>
  
  <pre><code>def openAbout(self, MainWindow):
      AboutDialog = QtGui.QDialog(MainWindow)
      aboutUi = Ui_AboutDialog()
      aboutUi.setupUi(AboutDialog)
      AboutDialog.setModal(True)
      AboutDialog.show()
  </code></pre>