[PyQt] QStandardItemModel best practice
Sebastian Elsner
sebastianelsner at freenet.de
Sun Apr 18 17:22:59 BST 2010
Try using QAbstractItemModel instead. ANd have a look at the table
examples coming with PyQt. They helped me a lot.
TheyAm 18.04.2010, 19:43 Uhr, schrieb Dom <dom at reality-debug.co.uk>:
> Hi-
>
> I'm looking to create a table with checkable items based off a
> dictionary using the QStandardItemModel class, what is the best practice
> to do this? I've looked at using the class directly and it seemed
> cumbersome to add the data to the table and I couldn't get data to
> display at all when I subclassed.
>
> class MyTableModel(QStandardItemModel):
> def __init__(self, datain, headerdata, parent=None, *args):
> """ datain: a list of lists headerdata: a list of strings """
> QStandardItemModel.__init__(self, 5, 6)
> self.arraydata = datain
> self.headerdata = headerdata
> def rowCount(self, parent):
> return len(self.arraydata)
> def columnCount(self, parent):
> return len(self.arraydata[0])
> def data(self, index, role):
> if not index.isValid():
> return QVariant()
> elif role != Qt.DisplayRole:
> return QVariant()
> return QVariant(self.arraydata[index.row()][index.column()])
>
> def headerData(self, col, orientation, role):
> if orientation == Qt.Horizontal and role == Qt.DisplayRole:
> return QVariant(self.headerdata[col])
> return QVariant()
>
> thanks
--
Erstellt mit Operas revolutionärem E-Mail-Modul: http://www.opera.com/mail/
More information about the PyQt
mailing list