QtPython QtreeWidget - sortingEnabled Problem

Threader Slash threaderslash at gmail.com
Tue Nov 17 00:34:34 CET 2009


Hello Everybody,

I trying to do a Qtreewidget to attend a customer design suggestion. I am
coding it on QtPython. I did a first try using Qt Designer, then generated
the code. But when I try to run it, an error comes out:

self.centralwidget.setSortingEnabled(__sortingEnabled)
AttributeError: setSortingEnabled

I googled around, but didn't find any solution for this problem, except some
suggestion just to simply delete the lines in the code that results in the
compiling error. But it didn't really help, because if you do so, it
triggers more error, just like that:

self.treeWidget.topLevelItem(0).child(1).setText(0,
QtGui.QApplication.translate("MainWindow", "Item Name", None,
QtGui.QApplication.UnicodeUTF8))
AttributeError: 'NoneType' object has no attribute 'setText'

Here is my current code to generate a nice simple QtreeWidget/View:

#//===========================================================//#
def color_setupUi(self, MainWindow,phrase):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
self.eqpt_centralwdg(MainWindow)
self.eqpt_retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
#//===========================================================//#
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")

item = QtGui.QTreeWidgetItem(self.colorTreeWidget)
item = QtGui.QTreeWidgetItem(self.colorTreeWidget)

self.centralwidget.setSortingEnabled(__sortingEnabled)
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)
self.colorTreeWidget.topLevelItem(0).setText(0,
QtGui.QApplication.translate("MainWindow", "Yellow", None,
QtGui.QApplication.UnicodeUTF8)
self.colorTreeWidget.topLevelItem(1).setText(0,
QtGui.QApplication.translate("MainWindow", "Blue", None,
QtGui.QApplication.UnicodeUTF8)
self.colorTreeWidget.setSortingEnabled(__sortingEnabled)
#//===========================================================//#

All other object I needed to implement on Qt using Designer and a little bit
of code has worked fine so far, e.g. inputLine, comboBox, TabWidget. I just
got stuck with this TreeWidget error.

Any hints or suggestion are highly appreciated and welcome.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091117/f06445de/attachment.html>


More information about the Python-list mailing list