LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-16-2009, 05:32 PM   #1
threaderslash
Member
 
Registered: Dec 2008
Location: HongKong
Distribution: Fedora/Centos/RedHat
Posts: 115

Rep: Reputation: 15
Cool 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:

Code:
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:

Code:
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:
Code:
#//===========================================================//#
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 had 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.
 
Old 11-16-2009, 08:38 PM   #2
threaderslash
Member
 
Registered: Dec 2008
Location: HongKong
Distribution: Fedora/Centos/RedHat
Posts: 115

Original Poster
Rep: Reputation: 15
Lightbulb yebah! solved...

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)
Hope this may help others too.

Last edited by threaderslash; 11-16-2009 at 08:45 PM.
 
  


Reply

Tags
member



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Solved Problem Second GCC-Pass(or gettext sanity check problem) hoes Linux From Scratch 0 09-04-2005 10:20 AM
Sound Card problem(every time i install linux i have diffirent hardware problem) jacka1l Linux - Newbie 7 08-11-2005 06:10 AM
Lan configuration problem - NFS boot problem - RX&TX packets errors 242VDM242 Linux - Networking 4 11-25-2004 01:35 PM
perl problem? apache problem? cgi problem? WorldBuilder Linux - Software 1 09-17-2003 07:45 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration