I'm working on a user interface in PyQt, and I'm running into a few problems trying to use QDialog. Essentially I have a main widget and a sub-widget, saved in separate .py files; I would like the sub-widget to open when I click a certain button in the main widget. This seems to be opening fine.
The issue comes with returning and closing. I have a "submit" button on my sub-widget - when the user clicks this button, I would like to return a value (a dictionary made from their input) to the main widget, and close the sub-widget. I can't seem to do either of these things with the code I have right now.
Applicable bits of code in the main widget (can add more to make it self-contained if the problem isn't obvious):
import SGROIWidget_ui
def retranslateUi(self, ROIGUI):
#ShowGroupROI is a push-button
self.ShowGroupROI.clicked.connect(self.ShowGroupROIFunction)
def ShowGroupROIFunction(self):
dialog = QDialog()
dialog.ui = SGROIWidget_ui.Ui_ShowGroupWidget()
dialog.ui.setupUi(dialog)
dialog.setAttribute(QtCore.Qt.WA_DeleteOnClose)
if dialog.exec_():
roiGroups=dialog.Submitclose()
print(roiGroups)
dialog.accept()
I never seem to hit the code after the if-statement.
The applicable code from my sub-widget (will include a bit more here):
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_ShowGroupWidget(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
self.setupUi(self)
def setupUi(self, ShowGroupWidget):
#sets up Submit button
def retranslateUi(self, ShowGroupWidget):
self.Submit.clicked.connect(self.Submitclose)
def Submitclose(self):
roiGroups={}
#roiGroups gets set up here as a dictionary
#It prints nicely from here so I know it's not the issue
return roiGroups
#I don't know if I can just do a return statement like this?
self.close()*
*I have tried ex.close() here as well but ex is not recognized when this widget is run as a dialog. It doesn't seem like it should get to this line because of the return statement, but I don't know how else to close this widget after the user hits "submit". Or should the dialog.accept() in my main widget handle that?
One last thing - do I need this in my sub-widget at all, since it's being run through my main widget instead?
if __name__=='__main__':
app=QtGui.QApplication(sys.argv)
ex=Ui_ShowGroupWidget()
ex.show()
sys.exit(app.exec_())
Thanks in advance! I am pretty new to PyQt so hopefully this is somewhat legible.