title: PyQt custom dialog -- how to get the return value?
body: <p>Using PyQt5, I'm trying to get a custom dialog (containing a simple QListWidget) to return a value.
  I know similar questions have been asked before but somehow I don't seem to get the answers to work.</p>
  
  <p>The custom dialog is in this class:</p>
  
  <pre><code>class ListSelection(QDialog):
      def __init__(self, item_ls, parent=None):
          super(ListSelection, self).__init__(parent)
          self.result = ""
          #================================================= 
          # listbox
          #================================================= 
          self.listWidget = QListWidget()
          for item in item_ls:
          w_item = QListWidgetItem(item)
          self.listWidget.addItem(w_item)
          self.listWidget.itemClicked.connect(self.OnSingleC lick)
          self.listWidget.itemActivated.connect(self.OnDoubl eClick)
          layout = QGridLayout()
          row=0
          layout.addWidget(self.listWidget,row,0,1,3) #col span=1, row span=3
          #================================================= 
          # OK, Cancel
          #================================================= 
          row +=1
          self.but_ok = QPushButton("OK")
          layout.addWidget(self.but_ok ,row,1)
          self.but_ok.clicked.connect(self.OnOk)
  
          self.but_cancel = QPushButton("Cancel")
          layout.addWidget(self.but_cancel ,row,2)
          self.but_cancel.clicked.connect(self.OnCancel)
  
          #================================================= 
          #
          #================================================= 
          self.setLayout(layout)
          self.setGeometry(300, 200, 460, 350)
  
      def OnSingleClick(self, item):
          self.result = item.text()
  
      def OnDoubleClick(self, item):
          self.result = item.text()
          self.close()
          return self.result
  
      def OnOk(self):
          if self.result == "":
              QMessageBox.information(self, "Error",
              "One item must be selected")
              return 
          self.close()
          return self.result
  
      def OnCancel(self):
          self.close()
  
      def GetValue(self):
          return self.result
  </code></pre>
  
  <p>And this is what the calling function does:</p>
  
  <pre><code>def SomeFunction()
      ls = ['apples','bananas','melons']
      lb = ListSelection(ls)
      if lb.exec_():
          value = lb.GetValue()
          print(value)
  </code></pre>
  
  <p>The problem is, this does not capture any value.</p>
  
  <p>Thanks!</p>