how do you reload a listView? When I add a object to LIBARY I want to reload the list so all items is showed. how do I do that?


here is my code

Qt Code:
  1. #------------------------------------------------------------
  2. #------------------------------------------------------------
  3.  
  4. # Hantera biblotek
  5. class manageLibary(QtGui.QDialog):
  6. def __init__(self, parent):
  7. QtGui.QDialog.__init__(self, parent)
  8. self.ui = ManageLibary()
  9. self.ui.setupUi(self)
  10. self.model = manageLibaryModel(self)
  11. self.ui.listView.setModel(self.model)
  12. self.connect(self.ui.pushButton, QtCore.SIGNAL("clicked()"), self.validateInput)
  13.  
  14.  
  15. def validateInput(self):
  16. if self.ui.lineEdit.text() != "":
  17. # make validator later here for
  18. LIBARY.append(bibliotek(self.ui.lineEdit.text()))
  19. print self.ui.lineEdit.text()
  20. print len(LIBARY)
  21. self.emit(QtCore.SIGNAL("dataChanged()"))
  22.  
  23.  
  24.  
  25. #------------------------------------------------------------
  26. # Manage Libary Model
  27. #------------------------------------------------------------
  28. #
  29. class manageLibaryModel(QtCore.QAbstractListModel):
  30. def __init__(self, parent):
  31. QtCore.QAbstractListModel.__init__(self, parent)
  32.  
  33.  
  34. def data(self, index, role):
  35. if role == QtCore.Qt.DisplayRole:
  36. return LIBARY[index.row()].name
  37.  
  38. elif role == QtCore.Qt.UserRole:
  39. return LIBARY[index.row()]
  40.  
  41. def rowCount(self, parent=QtCore.QModelIndex()):
  42. return len(LIBARY)
To copy to clipboard, switch view to plain text mode