Hello Everybody,
I have a QTreewidget that works fine if I have just one level on my treelist. If I decide to add child sublevels, it gives me an error. Here is the code, that works nice only without the "childs" lines on it (see after "child 1" and "child 2").
def eqpt_centralwdg(self,MainWindow):
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.colorTreeWidget = QtGui.QTreeWidget(self.centralwidget)
self.colorTreeWidget.setGeometry(QtCore.QRect(60, 60, 191, 141))
self.colorTreeWidget.setObjectName("colorTreeWidget")
# father root 1
item = QtGui.QTreeWidgetItem(self.colorTreeWidget)
#child 1 - from father 1
item = QtGui.QTreeWidgetItem(item)
#child 2 - from father 1
item = QtGui.QTreeWidgetItem(item)
# father root 2
item = QtGui.QTreeWidgetItem(self.colorTreeWidget)
self.connect(self.colorTreeWidget, QtCore.SIGNAL('itemClicked(QTreeWidgetItem*, int)'), self.eqpt_activateInput)
MainWindow.setCentralWidget(self.centralwidget)
def eqpt_retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8)
self.colorTreeWidget.headerItem().setText(0, QtGui.QApplication.translate("MainWindow", "color", None, QtGui.QApplication.UnicodeUTF8)
__sortingEnabled = self.colorTreeWidget.isSortingEnabled()
self.colorTreeWidget.setSortingEnabled(False)
# father root 1
self.colorTreeWidget.topLevelItem(0).setText(0, QtGui.QApplication.translate("MainWindow", "Yellow", None, QtGui.QApplication.UnicodeUTF8)
#child 1 - from father 1
self.colorTreeWidget.topLevelItem(0).child(0).setText(0, QtGui.QApplication.translate("MainWindow", "Yellow Sun", None, QtGui.QApplication.UnicodeUTF8))
#child 2 - from father 1
self.colorTreeWidget.topLevelItem(0).child(1).setText(0, QtGui.QApplication.translate("MainWindow", "Yellow Gold", None, QtGui.QApplication.UnicodeUTF8))
# father root 2
self.colorTreeWidget.topLevelItem(1).setText(0, QtGui.QApplication.translate("MainWindow", "Blue", None, QtGui.QApplication.UnicodeUTF8)
self.colorTreeWidget.setSortingEnabled(__sortingEnabled)
Here is the output, when it works
def eqpt_activateInput(self,item,col):
print "Qtree ok! pressed"
print item.text(col)
if I exclude the lines related to the "child 1" and "child 2" from the code, it runs. Otherwise, it gives me the error:
AttributeError: 'NoneType' object has no attribute 'setText'
I used the Qt Designer to generate the code, and added some lines to trigger events.
Any hints or suggestions are highly appreciated.