title: Block and hide QDialog: Alternative to exec_()?
body: <p>In my Qt-based application (built using PyQt 4.8.6), I have a class that is a subclass of QtGui.QDialog:</p>
  
  <pre><code>class ModelDialog(QtGui.QDialog):
      ...
  </code></pre>
  
  <p>When I run the application's user interface, I can display the QDialog like so:</p>
  
  <pre><code>def main():
      app = QtGui.QApplication(sys.argv)
      dialog = ModelDialog()
      dialog.exec_()
  </code></pre>
  
  <p>According to the <a href="http://doc.qt.nokia.com/latest/qdialog.html#exec" rel="nofollow">Qt docs</a> and the <a href="http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qdialog.html#exec" rel="nofollow">PyQt docs</a>, <code>exec_()</code> is a blocking function for this QDialog, which defaults to a modal window (which by definition prevents the user from interacting with any other windows within the application).  This is exactly what happens under normal circumstances.</p>
  
  <p>Recently, however, I've been working on a way to call through the entire QApplication using defaults for all input values, and not asking the user for any input.  The application behaves as expected except for one single aspect:  calling <code>dialog.exec_()</code> causes the modal dialog to be shown.</p>
  
  <p>The only workaround I've been able to find has been to catch the <code>showEvent</code> function and to promptly hide the window, but this still allows the QDialog object to be shown for a split second:</p>
  
  <pre><code>class ModelDialog(QtGui.QDialog):
      ...
      def showEvent(self, data=None):
          self.hide()
  </code></pre>
  
  <p>Is there a way to prevent the modal window from being shown altogether, while continuing to block the main event loop?  I'd love for there to be something like:</p>
  
  <pre><code>def main():
      app = QtGui.QApplication(sys.argv)
      dialog = ModelDialog()
      dialog.setHideNoMatterWhat(True)
      dialog.exec_()
  </code></pre>
  
  <p>(to that end, I tried using <code>QWidget.setVisible(False)</code>, but <code>dialog.exec_()</code> sets the dialog to be visible anyways, which is expected according to the <a href="http://doc.qt.nokia.com/latest/qwidget.html#visible-prop" rel="nofollow">Qt docs</a>)</p>