<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><pre>Hello Everybody,<br><br>I have a QTreewidget that works fine if I have just one level on my<br>
treelist. If I decide to add child sublevels, it gives me an error. Here is<br>the code, that works nice only without the "childs" lines on it (see after<br>
"child 1" and "child 2").<br><br> def eqpt_centralwdg(self,MainWindow):<br> self.centralwidget = QtGui.QWidget(MainWindow)<br> self.centralwidget.setObjectName("centralwidget")<br>
<br> self.colorTreeWidget = QtGui.QTreeWidget(self.centralwidget)<br> self.colorTreeWidget.setGeometry(QtCore.QRect(60, 60, 191, 141))<br> self.colorTreeWidget.setObjectName("colorTreeWidget")<br>
<br> # father root 1<br> item = QtGui.QTreeWidgetItem(self.colorTreeWidget)<br> #child 1 - from father 1<br> item = QtGui.QTreeWidgetItem(item)<br> #child 2 - from father 1<br> item = QtGui.QTreeWidgetItem(item)<br>
# father root 2<br> item = QtGui.QTreeWidgetItem(self.colorTreeWidget)<br><br> self.connect(self.colorTreeWidget,<br>QtCore.SIGNAL('itemClicked(QTreeWidgetItem*, int)'),<br>self.eqpt_activateInput)<br>
<br> MainWindow.setCentralWidget(self.centralwidget)<br><br> def eqpt_retranslateUi(self, MainWindow):<br> MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow",<br>"MainWindow", None, QtGui.QApplication.UnicodeUTF8)<br>
self.colorTreeWidget.headerItem().setText(0,<br>QtGui.QApplication.translate("MainWindow", "color", None,<br>QtGui.QApplication.UnicodeUTF8)<br> __sortingEnabled = self.colorTreeWidget.isSortingEnabled()<br>
self.colorTreeWidget.setSortingEnabled(False)<br> # father root 1<br> self.colorTreeWidget.topLevelItem(0).setText(0,<br>QtGui.QApplication.translate("MainWindow", "Yellow", None,<br>
QtGui.QApplication.UnicodeUTF8)<br> #child 1 - from father 1<br> self.colorTreeWidget.topLevelItem(0).child(0).setText(0,<br>QtGui.QApplication.translate("MainWindow", "Yellow Sun", None,<br>
QtGui.QApplication.UnicodeUTF8))<br> #child 2 - from father 1<br> self.colorTreeWidget.topLevelItem(0).child(1).setText(0,<br>QtGui.QApplication.translate("MainWindow", "Yellow Gold", None,<br>
QtGui.QApplication.UnicodeUTF8))<br><br> # father root 2<br> self.colorTreeWidget.topLevelItem(1).setText(0,<br>QtGui.QApplication.translate("MainWindow", "Blue", None,<br>QtGui.QApplication.UnicodeUTF8)<br>
<br> self.colorTreeWidget.setSortingEnabled(__sortingEnabled)<br><br><br>Here is the output, when it works<br><br> def eqpt_activateInput(self,item,col):<br> print "Qtree ok! pressed"<br> print item.text(col)<br>
<br>if I exclude the lines related to the "child 1" and "child 2" from the code,<br>it runs. Otherwise, it gives me the error:<br><br> AttributeError: 'NoneType' object has no attribute 'setText'<br>
<br><br>I used the Qt Designer to generate the code, and added some lines to trigger<br>events.<br><br>Any hints or suggestions are highly appreciated.<br></pre><input type="hidden"><input type="hidden"><div>
</div>
</blockquote></div><br>Solved!<br>Here is the solution:<br><br>parent1 = QtGui.QTreeWidgetItem(self.colorTreeWidget)<br>child1_1 = QtGui.QTreeWidgetItem()<br>child1_2 = QtGui.QTreeWidgetItem()<br>parent1.addChild(child1_1)<br>
parent1.addChild(child1_2)<br><br>Now it works properly.<br><br>Hope this may help others too.<br><input id="gwProxy" type="hidden"><input onclick="jsCall();" id="jsProxy" type="hidden"><div id="refHTML"></div>