[Qt-interest] QTreeWidget problem

NARCISO, Rui RUI.NARCISO at airbus.com
Wed Mar 11 10:59:24 CET 2009


Hi all

I have a problem with a QTreeWidget.
I can add items with no problems. When I remove them they also disappear from the view. However, after removing one item, the sorting of any column just makes everything go crazy. For example, I have one line selected and after sorting, each column has a different line selected ... moreover, widgets I have placed in one of the columns just randomly disappear when sorting ...

Any help ?

Btw, I'm coding in PyQt4 but it's easibly readable to you guys...

Here is the snippet:

    def addDisk(self, name, _path_, parent, level=0):
        filer, total, used, available, usedpercentage, path = self.folderSize("/".join(_path_.split('/')[: level+2]))
        try:
            name = _path_.split('/')[level+1]
            list = QStringList() << name << path << str("%.1f Gb" %(total))
        except TypeError:
            print "TypeError"
            list = QStringList() << name << "" << ""
            
        item = QTreeWidgetItem(list)
        print parent.text(0), item.text(0), self.hasChild(parent, item)
        if self.hasChild(parent, item) == -1:
            parent.addChild(item)
            try:
                bar = usedSpaceBar(value=int(usedpercentage.replace('%','')), label=str( "%.1f Gb" %(used)), parent=self)
                self.tree.setItemWidget(item, 3, bar)
            except ValueError:
                pass
        else:
            item = parent.child(self.hasChild(parent, item))
                
        if level+1 < len(_path_.split('/'))-1:
            self.addDisk(name, _path_,item, level+1)

    def hasChild(self, parent, child):
        for index in range(parent.childCount()):
            if parent.child(index).text(1) == child.text(1):
                return index
        return -1

    def removeDisk(self):
        for disk in self.tree.selectedItems():
            disk.parent().removeChild(disk)



The information in this e-mail is confidential. The contents may not be disclosed or used by anyone other then the addressee. Access to this e-mail by anyone else is unauthorised.
If you are not the intended recipient, please notify Airbus immediately and delete this e-mail.
Airbus cannot accept any responsibility for the accuracy or completeness of this e-mail as it has been sent over public networks. If you have any concerns over the content of this message or its Accuracy or Integrity, please contact Airbus immediately.
All outgoing e-mails from Airbus are checked using regularly updated virus scanning software but you should take whatever measures you deem to be appropriate to ensure that this message and any attachments are virus free.





More information about the Qt-interest-old mailing list