On Thu, 18 Dec 2008 13:11:19 +0100, Ralph Kube <[email protected]> wrote: > Hey people, > I have a simple question about using QListView in my application. > Lets say, I want QListView to display a number of strings. > On the command line the following works: > > str_list = ['str1', 'str2', ... , 'strn'] > qstr = QStringList(str_list) > qstr_model = QStringListModel(qstr) > lv = QListView() > lv.setModel(qstr_model) > lv.show() > > I get a ListView with the strings in there. Great. > Now I got the following code in my app and it doesn't show anything: > > > class ListViewTest(QtGui.QMainWindow): > def __init__(self, *args): > apply(QtGui.QMainWindow.__init__, (self, ) + args) > > self.setGeometry(300, 300, 300, 50) > self.setWindowTitle('ListViewTest') > > qstr = QtCore.QStringList(QtCore.QString('foo')) > qstr_model = QtGui.QStringListModel(qstr) > self.lv = QtGui.QListView(self) > self.lv.move(120,10) > self.lv.setModel(qstr_model) > > self.pb = QtGui.QPushButton('Update', self) > self.pb.move(10,10) > > QtCore.QObject.connect(self.pb, QtCore.SIGNAL('clicked()'), > self.update_list) > > > def update_list(self): > > qstr = QtCore.QStringList(QtCore.QString('bar')) > qstr_model = QtGui.QStringListModel(qstr) > self.lv.setModel(qstr_model) > print 'Button pressed' > > > app = QtGui.QApplication(sys.argv) > mywin = ListViewTest() > mywin.show() > app.exec_() > > > Any ideas about that? I surely am confused.
Keep an explicit reference to your model. It is being garbage collected. Phil _______________________________________________ PyQt mailing list [email protected] http://www.riverbankcomputing.com/mailman/listinfo/pyqt
