title: PyQt4: Create a custom dialog that returns parameters
body: <p>I'm attempting to add a custom dialog box to my current GUI that can be launched for the user to set some parameters. Ideally, I would like to create the custom dialog using QtDesigner. Below is the code generated by <code>pyuic4</code> from the QtDesigner ui code for the dialog box.</p>
  
  <pre><code>from PyQt4 import QtCore, QtGui
  
  class Ui_Dialog(object):
      def setupUi(self, Dialog):
          Dialog.setObjectName("Dialog")
          Dialog.resize(508, 300)
          self.buttonBox = QtGui.QDialogButtonBox(Dialog)
          self.buttonBox.setGeometry(QtCore.QRect(150, 250, 341, 32))
          self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
          self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
          self.buttonBox.setObjectName("buttonBox")
          self.label = QtGui.QLabel(Dialog)
          self.label.setGeometry(QtCore.QRect(10, 120, 181, 31))
          font = QtGui.QFont()
          font.setPointSize(16)
          self.label.setFont(font)
          self.label.setObjectName("label")
          self.sl_value = QtGui.QSlider(Dialog)
          self.sl_value.setGeometry(QtCore.QRect(220, 120, 161, 31))
          self.sl_value.setOrientation(QtCore.Qt.Horizontal)
          self.sl_value.setObjectName("sl_value")
          self.ed_value = QtGui.QLineEdit(Dialog)
          self.ed_value.setGeometry(QtCore.QRect(400, 120, 41, 31))
          font = QtGui.QFont()
          font.setPointSize(16)
          self.ed_value.setFont(font)
          self.ed_value.setObjectName("ed_value")
          self.retranslateUi(Dialog)
          QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), Dialog.accept)
          QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), Dialog.reject)
          QtCore.QMetaObject.connectSlotsByName(Dialog)
  
  
      def retranslateUi(self, Dialog):
          Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))
          self.label.setText(QtGui.QApplication.translate("Dialog", "Set example value:", None, QtGui.QApplication.UnicodeUTF8))
  </code></pre>
  
  <p>This is saved in <code>Sub2.py</code>
  Then, in my main python file, I add </p>
  
  <pre><code>from Sub2 import Ui_Dialog
  </code></pre>
  
  <p>I create a new class called <code>StartSub2</code> with the following code</p>
  
  <pre><code>class StartSub2(QtGui.QDialog):
      def __init__(self,parent=None):
          QtGui.QDialog.__init__(self,parent)
          self.ui = Ui_Dialog
          self.ui.setupUi(self)
  </code></pre>
  
  <p>Then finally in inside my main GUI there's a function with the following code that should launch the dialog</p>
  
  <pre><code>def exampleSubGui(self):
      dialog = StartSub2(self)
      result = dialog.exec_()
  </code></pre>
  
  <p>Please note that the dialog is not done. Once I resolve how to even launch it I will add signal/slot connections for the slider and edit box. Also, if I understand it correctly, I need to overload the <code>accept()</code> method to return the user's input.</p>
  
  <p>The first problem I run into is with the <code>__init__</code> method of <code>StartSub2</code>. I get the following error: </p>
  
  <pre><code>TypeError: unbound method setupUi() must be called with Ui_Dialog instance as
  first argument (got StartSub2 instance instead)
  </code></pre>
  
  <p>I'm attempting to take the same approach that the main GUI is taking which uses the following code</p>
  
  <pre><code>class StartQT4(QtGui.QMainWindow):
      def __init__(self, parent=None):
          QtGui.QWidget.__init__(self, parent)
          self.ui = Ui_MainWindow()
          self.ui.setupUi(self)
  </code></pre>
  
  <p>But this does not complain about <code>setupUi()</code> getting a <code>StartQT4</code> instance instead of a <code>Ui_MainWindow</code> instance. Can anyone explain the proper way to accomplish what I'm trying to do? Or can somebody point me to a clear example or reference? Please let me know if you need more information or clarification.</p>