View Single Post
Posts: 118 | Thanked: 26 times | Joined on Jun 2008
#7
Just connect the accepted() signal to a function in your class that does whatever work you need to do. It's pretty simple, as the dialog automatically closes. If you want to do some stuff in the event that the dialog is rejected, just connect the rejected() signal to a different function. Here's an example that subclasses the Qt Designer created classes:

Code:
class settingsDialog(QDialog, Ui_settingsDialog):
    def __init__(self, parent, gconfClient):
        self.parent = parent
        QDialog.__init__(self, parent)
        self.gconfClient = gconfClient
        self.setupUi(self)
        
        self.googlePasswordLineEdit.setEchoMode(QLineEdit.Password)
        googlename = self.gconfClient.get_string('/apps/event2gcal/googlename')
        if googlename != None:
            self.googleUsernameLineEdit.setText(googlename)
        googlepass = self.gconfClient.get_string('/apps/event2gcal/googlepass')
        if googlepass != None:
            self.googlePasswordLineEdit.setText(googlepass)
        dbuslisten = self.gconfClient.get_bool('/apps/event2gcal/dbuslisten')
        if dbuslisten != None:
            self.dBusListenerCheckBox.setChecked(self.gconfClient.get_bool('/apps/event2gcal/dbuslisten'))
        
        if googlename != None and googlepass != None:
            calDict = self.parent.googleCalendar.getCalendars()    
            self.populateCalendar(calDict)
            
        self.connect(self.buttonBox, SIGNAL("accepted()"), self.saveSettings)
        
        self.exec_()
        
    def saveSettings(self):
        # Read values of widgets and save in GConf
        # We should probably sanity check the values at some point..
        self.gconfClient.set_string('/apps/event2gcal/googlename', str(self.googleUsernameLineEdit.text()))
        self.gconfClient.set_string('/apps/event2gcal/googlepass', str(self.googlePasswordLineEdit.text()))
        self.gconfClient.set_string('/apps/event2gcal/googlecal', 
                                    str(self.calendarComboBox.itemData(self.calendarComboBox.currentIndex()).toString()))
        self.parent.googleEditUri = str(self.calendarComboBox.itemData(self.calendarComboBox.currentIndex()).toString())
        print "Saving edit uri: " + str(self.calendarComboBox.itemData(self.calendarComboBox.currentIndex()).toString()) + "\n"
        self.gconfClient.set_bool('/apps/event2gcal/dbuslisten', self.dBusListenerCheckBox.isChecked())

    def populateCalendar(self, calDict):
        for calName in calDict:
            self.calendarComboBox.addItem(calName, calDict[calName])
Ironically, too much thinking has been what gets me in trouble with Qt.
 

The Following User Says Thank You to wierdo For This Useful Post: