implor
16th May 2010, 21:24
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
#------------------------------------------------------------
#------------------------------------------------------------
# Hantera biblotek
class manageLibary(QtGui.QDialog):
def __init__(self, parent):
QtGui.QDialog.__init__(self, parent)
self.ui = ManageLibary()
self.ui.setupUi(self)
self.model = manageLibaryModel(self)
self.ui.listView.setModel(self.model)
self.connect(self.ui.pushButton, QtCore.SIGNAL("clicked()"), self.validateInput)
def validateInput(self):
if self.ui.lineEdit.text() != "":
# make validator later here for
LIBARY.append(bibliotek(self.ui.lineEdit.text()))
print self.ui.lineEdit.text()
print len(LIBARY)
self.emit(QtCore.SIGNAL("dataChanged()"))
#------------------------------------------------------------
# Manage Libary Model
#------------------------------------------------------------
#
class manageLibaryModel(QtCore.QAbstractListModel):
def __init__(self, parent):
QtCore.QAbstractListModel.__init__(self, parent)
def data(self, index, role):
if role == QtCore.Qt.DisplayRole:
return LIBARY[index.row()].name
elif role == QtCore.Qt.UserRole:
return LIBARY[index.row()]
def rowCount(self, parent=QtCore.QModelIndex()):
return len(LIBARY)
here is my code
#------------------------------------------------------------
#------------------------------------------------------------
# Hantera biblotek
class manageLibary(QtGui.QDialog):
def __init__(self, parent):
QtGui.QDialog.__init__(self, parent)
self.ui = ManageLibary()
self.ui.setupUi(self)
self.model = manageLibaryModel(self)
self.ui.listView.setModel(self.model)
self.connect(self.ui.pushButton, QtCore.SIGNAL("clicked()"), self.validateInput)
def validateInput(self):
if self.ui.lineEdit.text() != "":
# make validator later here for
LIBARY.append(bibliotek(self.ui.lineEdit.text()))
print self.ui.lineEdit.text()
print len(LIBARY)
self.emit(QtCore.SIGNAL("dataChanged()"))
#------------------------------------------------------------
# Manage Libary Model
#------------------------------------------------------------
#
class manageLibaryModel(QtCore.QAbstractListModel):
def __init__(self, parent):
QtCore.QAbstractListModel.__init__(self, parent)
def data(self, index, role):
if role == QtCore.Qt.DisplayRole:
return LIBARY[index.row()].name
elif role == QtCore.Qt.UserRole:
return LIBARY[index.row()]
def rowCount(self, parent=QtCore.QModelIndex()):
return len(LIBARY)