<!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>
&nbsp;&nbsp;&nbsp; def __init__(self, datain, headerdata, parent=None, *args): <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; """ datain: a list of lists headerdata: a list of strings """<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; QStandardItemModel.__init__(self, 5, 6) <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.arraydata = datain<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.headerdata = headerdata<br>
&nbsp;<br>
&nbsp;&nbsp;&nbsp; def rowCount(self, parent): <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return len(self.arraydata) <br>
&nbsp;<br>
&nbsp;&nbsp;&nbsp; def columnCount(self, parent): <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return len(self.arraydata[0]) <br>
&nbsp;<br>
&nbsp;&nbsp;&nbsp; def data(self, index, role): <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if not index.isValid(): <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return QVariant() <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; elif role != Qt.DisplayRole: <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return QVariant() <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return QVariant(self.arraydata[index.row()][index.column()]) <br>
<br>
&nbsp;&nbsp;&nbsp; def headerData(self, col, orientation, role):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if orientation == Qt.Horizontal and role == Qt.DisplayRole:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return QVariant(self.headerdata[col])<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return QVariant()<br>
</font></font>
<div class="moz-signature"><br>
thanks<br>
</div>
</body>
</html>