> ----------  ----------
> From: Threader Slash <threadersl...@gmail.com>
> To: python-list@python.org
> Date: Tue, 17 Nov 2009 10:34:34 +1100
> Subject: QtPython QtreeWidget - sortingEnabled Problem
> 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.
>
> ----------  ----------
>


Here is the solution:
1. delete/comment only the following line:
#self.centralwidget.setSortingEnabled(__sortingEnabled)

Then code:
[code]
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.connect(self.colorTreeWidget,
QtCore.SIGNAL('itemClicked(QTreeWidgetItem*, int)'),
self.eqpt_activateInput)

    MainWindow.setCentralWidget(self.centralwidget)

def eqpt_activateInput(self,item,col):
    print "Qtree ok! pressed"
    print item.text(col)
[/code]

Hope this may help others too.
ThreaderSlash
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to