LinuxQuestions.org
Visit Jeremy's Blog.
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-17-2009, 12:28 AM   #1
threaderslash
Member
 
Registered: Dec 2008
Location: HongKong
Distribution: Fedora/Centos/RedHat
Posts: 115

Rep: Reputation: 15
Cool Qt Python : QTreeWidget Child Problem


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").

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

Original Poster
Rep: Reputation: 15
Lightbulb

Solved!
Here is the solution:
Code:
parent1 = QtGui.QTreeWidgetItem(self.colorTreeWidget)
child1_1 = QtGui.QTreeWidgetItem()
child1_2 = QtGui.QTreeWidgetItem()
parent1.addChild(child1_1)
parent1.addChild(child1_2)
Now it works properly.

Hope this may help others too.

Last edited by threaderslash; 11-17-2009 at 08:39 PM.
 
  


Reply

Tags
member


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Difference between Child THREAD and Child PROCESS whho Linux - Newbie 12 02-16-2015 12:22 AM
QtPython QtreeWidget - sortingEnabled Problem threaderslash Programming 1 11-16-2009 08:38 PM
How to kill a Child and all its subsequent child process in C shayer009 Programming 3 12-04-2007 12:40 AM
python problem - compiled from source - python -V still showing old version txm123 Linux - Newbie 1 02-15-2006 11:05 AM
Killing a child process from another child marri Programming 6 10-01-2004 07:08 PM

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

All times are GMT -5. The time now is 09:39 AM.

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