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

Oscar Cossu zerozerosette at gmail.com
Fri Sep 8 14:23:50 BST 2006


Ok, I have to post my code because your suggest doesn't work (probably i
miss something).


class DomModel(QtCore.QAbstractItemModel):
    def __init__(self, document, parent = None):
        QtCore.QAbstractItemModel.__init__(self, parent)

        self.domDocument = document   ##this is a QDomDocument object

        self.rootItem = DomItem(self.domDocument, 0)

     ## some useful methods
    def columnCount(self, parent):
    def data(self, index, role):
    def headerData(self, section, orientation, role):
    def index(self, row, column, parent):
    def parent(self, child):
    def rowCount(self, parent):
    def findNodeByTagNameID(self,tagName,id):
    def validateDom(self,nodo):


    def removeRows(self,arow,count,parent):

          self.beginRemoveRows(parent,arow,arow+count-1)

                for ii in range(count):
                     ##code for removing a row from QDomDocument here

          self.endRemoveRows()
          return True



This is my model class. When i remove a row the qtreeview repaint the tree
but the row deleted isn't the one i've selected.
example:

the treeview show:

document
     element1
     element2
     element3

pick  elements2 for removing.

treeview update after removing but show:

document
    element1
    element2



Now, if i do:

print  qtreeview.model().domDocument.toString()

the result is:

document
     element1
     element3

so, the model is changed right. the removed element is the one that i
picked.

Any idea?


p.s. apologise for my english...hope it's understandable




2006/9/8, Andreas Pakulat <apaku at gmx.de>:
>
> On 08.09.06 10:38:51, Oscar Cossu wrote:
> > thank you for the advice, I have read the doc again (and again and
> again).
> > Now, I use a QTreeView ,what i have to do ?
> >
> > QTreeView::rowsAboutToBeRemoved(param)
> >
> > treeviewobj.model().removeRow(param)
> >
> > QTreeView::rowsRemoved(param)
>
> No.
>
> > or just call removeRow() that call itself beginRemoveRow and
> endRemoveRow  ?
>
> Well, you said you have your own model, don't you? In there you've got
> your removeRows() function. If that one is implemented by doing
> something like
>
> beginRemoveRows(parent(), beginRow, endRow);
> <code that deletes the stuff from the underlying data, i.e. the xml tree>
> endRemoveRows();
>
> Then you're done. You can now use the model's removeRows() function to
> remove rows. The same works for columns.
>
> If it still doesn't work for you, please consider posting the important
> parts of your model. (i.e. leave out the data, index, parent, *count
> functions).
>
> Andreas
>
> > 2006/9/7, Andreas Pakulat <apaku at gmx.de>:
> > >
> > >On 07.09.06 16:44:23, Oscar Cossu wrote:
> > >> Hy all,  I set the model of a QTreeView with an object that is a
> > >subclass of
> > >> QAbstractItemModel.
> > >> When I change the model (ex. deleting a row) and emit layoutChanged()
> > >> signal, the treeModel should update the view, but errors occur.
> > >
> > >Read the Qt documentation on model/view again. You shouldn't use
> > >layoutChanged() but call QAbstractItemModel::beginRemoveRows() and
> > >::endRemoveRows (the same for inserting rows).
> > >
> > >Andreas
> > >
> > >--
> > >Accent on helpful side of your nature.  Drain the moat.
> > >
> > >_______________________________________________
> > >PyKDE mailing list    PyKDE at mats.imk.fraunhofer.de
> > >http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
> > >
>
> > _______________________________________________
> > PyKDE mailing list    PyKDE at mats.imk.fraunhofer.de
> > http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
>
>
> --
> Keep it short for pithy sake.
>
> _______________________________________________
> 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/20060908/b4215735/attachment.html


More information about the PyQt mailing list