I\'m using pyqt4 with python 2.7 and I have a list view widget that I can\'t add items to it
# -*- coding: utf-8 -*-
# Form implementation generated from r
QListWidget
is a class of higher level that makes the developer can handle it easily, for example QListWidget
has a model of type QStantandardItemModel
that can not be accessed, in addition to built the QListWidgetItem
to handle the data, as you have seen is simple add data through functions like addItem()
or addItems()
.
On the other hand QListView
, from which QListWidget
inherits, is of lower level, where you can customize many things, using custom models, etc.
You can use both:
self.listView = QtGui.QListView(Dialog)
self.listView.setObjectName(_fromUtf8("listView"))
entries = ['one','two', 'three']
model = QtGui.QStandardItemModel()
self.listView.setModel(model)
for i in entries:
item = QtGui.QStandardItem(i)
model.appendRow(item)
self.gridLayout.addWidget(self.listView, 1, 0, 1, 2)
self.listwidget = QtGui.QListWidget(Dialog)
entries = ['one','two', 'three']
self.listwidget.addItems(entries)
self.gridLayout.addWidget(self.listwidget, 1, 0, 1, 2)