[PyKDE] [PyQt]: how to refresh a QTreeView widget?

Oscar Cossu zerozerosette at gmail.com
Mon Sep 11 08:44:25 BST 2006


In this way works. Thank you so much Andreas, you've saved my life...

2006/9/8, Andreas Pakulat <apaku at gmx.de>:
>
> On 08.09.06 16:29:32, Oscar Cossu wrote:
> >    def child(self, i):
> >        if self.childItems.has_key(i):
> >            return self.childItems[i]
> >
> >        if i >= 0 and i < self.domNode.childNodes().count():
> >            childNode = self.domNode.childNodes().item(i)
> >            childItem = DomItem(childNode, i, self)
> >            self.childItems[i] = childItem
> >            return childItem
>
> I think the problem lies here, for caching you put the child nodes into
> a dict, but in the removeRows function, you never update this dict. Now
> when a row is removed the tree thinks there are only 2 childs left and
> thus always asks for items 0 and 1. Due to the dict still containing a
> reference to the DomItem and the underlying QDomElement you return the
> wrong element.
>
> >    def findNodeByTagNameID(self,tagName,id):
> >        element = self.domDocument.elementsByTagName(tagName)
> >        for e in  range(element.length()) :
> >            tmp=element.item(e).attributes().namedItem("id").nodeValue()
> >            if  tmp==id:
> >                return element.item(e)
> >
> >        return None
> >
> >    def removeRows(self,arow,count,parent):
> >          print "removeRow"
> >          self.beginRemoveRows(parent,arow,arow+count-1)
> >          for ii in range(count):
> >              nodoIndex=self.index(arow+ii,0,parent)
> >              NomeNodo= nodoIndex.data().toString()
> >              IdNodo=self.index(arow+ii,1,parent).data().toString()
> >
> >              if IdNodo.contains("id"):
> >                  i=IdNodo.indexOf("id")
> >                  i=IdNodo.indexOf("\"",i)
> >                  f=IdNodo.indexOf("\"",i+1)
> >                  IdNodo=IdNodo.mid(i+1,f-i-1)
> >              else:
> >                  return False
> >
> >              nodo=self.findNodeByTagNameID(NomeNodo,IdNodo)
> >              nodo.parentNode().removeChild(nodo)
>
> Why do you make it so complicated? You have a row and the parent. Just
> use something like
>
> parentdomitem = index(parent.internalPointer().row(),0, parent.parent
> ()).internalPointer()
> childdomitem = parentdomitem.child(arow+ii)
> childdomitem.node.parentNode().removeChild(childdomitem.node)
> del parentdomitem.childItems[arow+ii]
>
> I think that should do it inside the for loop.
>
> Andreas
>
> --
> Green light in A.M. for new projects.  Red light in P.M. for traffic
> tickets.
>
> _______________________________________________
> PyKDE mailing list    PyKDE at mats.imk.fraunhofer.de
> http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20060911/6efcfe00/attachment.html


More information about the PyQt mailing list