<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><br></div><div>Right. Thanks for pointing out that I still need to explicitly pass "self."</div><div><br></div><div>I'm still not getting checkboxes displayed in the tree widget, though. I believe the problem is in the nested return value in the model's data() method. </div><div><br></div><div>The C++ example code I'm following uses a QMap data structure to hold checkState values. After reading Assistant notes, a python dir(QtCore), and some googling, I've found that QMap is not implemented in PyQt. So I'm using a Dict instead. Still, my app complains:</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>TypeError: invalid result type from DirModel.data()</div><div><br></div><div><br></div><div>Here's the C++ code I'm following:</div><div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "> <span style="color: #aa0d91">virtual</span> QVariant data(<span style="color: #aa0d91">const</span> QModelIndex &index, <span style="color: #aa0d91">int</span> role = Qt::DisplayRole) <span style="color: #aa0d91">const</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "> {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "> <span style="color: #aa0d91">if</span> (role == Qt::CheckStateRole && index.column() == <span style="color: #1c00cf">0</span>) {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "> <span style="color: #aa0d91">return</span> checkstates.value(fileInfo(index).absoluteFilePath(), Qt::Unchecked);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "> }</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "> <span style="color: #aa0d91">return</span> QDirModel::data(index, role);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "> }</div><div><font class="Apple-style-span" face="Monaco" size="2"><span class="Apple-style-span" style="font-size: 10px;"><br></span></font></div><div><font class="Apple-style-span" face="Monaco" size="2"><span class="Apple-style-span" style="font-size: 10px;"><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(170, 13, 145); ">private<span style="color: #000000">:</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "> QMap<QString, Qt::CheckState> checkstates;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; ">};</div><div><br></div><div><br></div></span></font></div></div><div><br></div><div><br></div><div>Here's my code:</div><div><br></div><div><div>class DirModel(QtGui.QDirModel):</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>def __init__(self, parent=None):</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>QtGui.QDirModel.__init__(self, parent)</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>self.checkstates = {}</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>def data(self, index, role=QtCore.Qt.DisplayRole):</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>if (role == QtCore.Qt.CheckStateRole and index.column() == 0):</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>self.checkstates[self.fileInfo(index).absoluteFilePath()] = QtCore.Qt.Checked</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>return self.checkstates[self.fileInfo(index).absoluteFilePath()] # <-- problem???</div><div><span class="Apple-tab-span" style="white-space:pre">                </span></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>return QtGui.QDirModel.data(self, index, role)</div><div><br></div></div><div><br></div><div><br></div><div>Thanks in advance for your suggestions!</div><div>Scott</div><div><br></div><div><br></div><div><br></div><br><div><div>On Jul 9, 2008, at 11:36 PM, Phil Thompson wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">On Wed, 9 Jul 2008 22:39:27 -0700, Scott Frankel <<a href="mailto:frankel@circlesfx.com">frankel@circlesfx.com</a>><br>wrote:<br><blockquote type="cite"><br></blockquote><blockquote type="cite">Hello,<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">I just joined this list and am new to PyQt (and Qt). I've scanned the <br></blockquote><blockquote type="cite">archives, but I'm not sure even what I'm looking for to answer my <br></blockquote><blockquote type="cite">question.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">I'm looking over some C++ code, trying to rewrite it in Python. (My <br></blockquote><blockquote type="cite">Spanish is much better than my C++!) I'm sub-classing and extending <br></blockquote><blockquote type="cite">QDirModel and getting the following error:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><span class="Apple-tab-span" style="white-space:pre">        </span>TypeError: first argument of unbound method QDirModel.data() must be <br></blockquote><blockquote type="cite">a QDirModel instance<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">The C++ methods are:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"> virtual QVariant data(const QModelIndex &index, int role = <br></blockquote><blockquote type="cite">Qt::DisplayRole) const<br></blockquote><blockquote type="cite"> {<br></blockquote><blockquote type="cite"> if (role == Qt::CheckStateRole && index.column() == 0) {<br></blockquote><blockquote type="cite"> return <br></blockquote><blockquote type="cite">checkstates.value(fileInfo(index).absoluteFilePath(), Qt::Unchecked);<br></blockquote><blockquote type="cite"> }<br></blockquote><blockquote type="cite"> return QDirModel::data(index, role);<br></blockquote><blockquote type="cite"> }<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">My translation so far looks like this:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">[ ... ]<br></blockquote><blockquote type="cite">class DirModel(QtGui.QDirModel):<br></blockquote><blockquote type="cite"><span class="Apple-tab-span" style="white-space:pre">        </span>def data(self, index, role=QtCore.Qt.DisplayRole):<br></blockquote><blockquote type="cite"><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>if (role == QtCore.Qt.CheckStateRole and index.column() == 0):<br></blockquote><blockquote type="cite"><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>return checkstates.value(fileInfo(index).absoluteFilePath(), <br></blockquote><blockquote type="cite">QtCore.Qt.Unchecked)<br></blockquote><blockquote type="cite"><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>return QtGui.QDirModel.data(index, role)<br></blockquote><blockquote type="cite">[ ... ]<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Not sure how to make the first argument (index or self?) be a <br></blockquote><blockquote type="cite">QDirModel instance. Ultimately I'm hoping for a directory tree with <br></blockquote><blockquote type="cite">check boxes.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Suggestions?<br></blockquote><br>When using an unbound method (including __init__()) you must explicitly<br>pass self. So...<br><br> return QtGui.QDirModel.data(self, index, role)<br><br>Phil<br><br><br></blockquote></div><br><div> <span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><div style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><div>Scott Frankel</div><div>President/VFX Supervisor</div><div>Circle-S Studios</div><div>510-339-7477 (o)</div><div>510-332-2990 (c)</div><div><br class="khtml-block-placeholder"></div><div><br class="khtml-block-placeholder"></div><br class="Apple-interchange-newline"></span></span></span></span></div></span> </div><br></body></html>