I try to insert a list of items in my QtreeWidget columns: each data is inserted in each column so there are as many item as columns. I am using the MVC architecture but the insertion failed!

This is my view:

def addContact(self, list):#add contact to my QTreeWidget
    list=[] #list of contact
    items=[]; #list of item

    self.treeWidget.setColumnCount(4);

    for i in list:
        items.append(QtGui.QTreeWidgetItem(list[i])); #create a QtreeWidgetItem's and append them
        items.setText(i,items[i])
        self.treeWidget.insertTopLevelItem(item[i]) #add all in my tree


class view_dialog(QtGui.QDialog, Ui_Dialog):
    def __init__(self):
        QtGui.QDialog.__init__(self)
        Ui_Dialog.__init__(self)
        self.setupUi(self)

    def readData(self): #read data entered by user
        nom=self.nom_line.text()
        prenom=self.prenom_line.text()
        tel=self.tel_line.text()
        adresse=self.adresse_line.text()

        contact=[nom, prenom, tel, adresse]

        return contact

    def clearData(self): # clear data
       self.nom_line.clear()
       self.prenom_line.clear()
       self.tel_line.clear()
       self.adresse_line.clear()

this is my model:

class modelContact:
    def __init__(self):
        self.contact=[] #Create a list of Contact

    def AddContact(self, nom, prenom, tel, adresse):#GetContact from my QList
       self.contact.append(nom);
       self.contact.append(prenom);
       self.contact.append(tel);
       self.contact.append(adresse);

and this is my controller:

def addContactToPhoneBook(self):
    list=self.dialog.readData()
    self.window.addContact(list)
    self.dialog.clearData()

Someone can help me to find what is wrong?

Related posts

Recent Viewed