I'm designing this thing on Qt Designer using PyQt. So I have a QMainWindow
from where the user can open a QDialog
to Input some data I'm saving in a Json file (AddUser function below)
What I want is when the AddUser push button is clicked, from the AddUser function, How can I Add a new Item in a Combobox that is defined in the MainWindow Class ?
Here is the code of the two classes
import ui.mainwindow as MnWindow
import ui.AddUserDialog as AddUserDialog
#First GUI
class MainWindow(QMainWindow,MnWindow.Ui_MainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.setupUi(self)
#Second GUI
class AddUserDialog(QDialog,AddUserDialog.Ui_Dialog):
def __init__(self,parent=None):
super(AddUserDialog,self).__init__(parent)
self.setupUi(self)
self.pushButtonAddUser.clicked.connect(self.AddUser)
def AddUser(self):
DateDeNaissance = self.dateEditDateDeNaissance.date().toString(Qt.ISODate)
DateDeSortie = self.dateEditDateDeSortie.date().toString(Qt.ISODate)
new_user = {
'firstname' : self.lineEditPrenom.text(),
'lastname' : self.lineEditNom.text(),
'DateDeNaissance' : DateDeNaissance[-2:] + DateDeNaissance[5:7] + DateDeNaissance[:4],
'LieuDeNaissance' : self.lineEditLieuNaissance.text(),
'Adresse' : self.lineEditAdresse.text(),
'Ville' : self.lineEditVille.text(),
'CodePostal' : self.lineEditCodePostal.text(),
'DateDeSortie' : DateDeSortie[-2:] + DateDeSortie[5:7] + DateDeSortie[:4],
'Heure' : str(self.timeEditSortie.time().hour()),
}
with open('TestJson.json','r') as f:
data = json.load(f)
data['users'].append(new_user)
with open('TestJson.json','w') as f:
json.dump(data,f,indent=3)
MainWindow.UserComboBox.addItem(new_user['firstname'] + ' ' + new_user['lastname'])
The last line the incorrect of course, How can I do that properly ?
PS: I've read that I need to inherit from MainWindow Class, but I've been trying that with no success.