<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body bgcolor="#ffffff" text="#000000">
<font size="-1"><font face="Helvetica">Hi-<br>
<br>
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. <br>
<br>
class MyTableModel(QStandardItemModel): <br>
def __init__(self, datain, headerdata, parent=None, *args): <br>
""" datain: a list of lists headerdata: a list of strings """<br>
QStandardItemModel.__init__(self, 5, 6) <br>
self.arraydata = datain<br>
self.headerdata = headerdata<br>
<br>
def rowCount(self, parent): <br>
return len(self.arraydata) <br>
<br>
def columnCount(self, parent): <br>
return len(self.arraydata[0]) <br>
<br>
def data(self, index, role): <br>
if not index.isValid(): <br>
return QVariant() <br>
elif role != Qt.DisplayRole: <br>
return QVariant() <br>
return QVariant(self.arraydata[index.row()][index.column()]) <br>
<br>
def headerData(self, col, orientation, role):<br>
if orientation == Qt.Horizontal and role == Qt.DisplayRole:<br>
return QVariant(self.headerdata[col])<br>
return QVariant()<br>
</font></font>
<div class="moz-signature"><br>
thanks<br>
</div>
</body>
</html>