[PyKDE] Problem with setModel on QTreeView

Andreas Pakulat apaku at gmx.de
Sun Jan 22 12:41:39 GMT 2006

On 22.01.06 11:34:34, Phil Thompson wrote:
> On Sunday 22 January 2006 12:53 am, Andreas Pakulat wrote:
> > Hi,
> >
> > using setModel() on a QTreeView results in the TreeView "loosing" it's
> > model, if I don't save a separate reference to it. Following code
> > doesn't work:
> >
> > tree = QtGui.QTreeView()
> > tree.setModel(SomeTreeModel(tree))
> > tree.show()
> >
> > The tree is empty, however first creating a variable pointing to the
> > model and then using setModel() with that variable works.
> >
> > I wouldn't bother writing this if this would be the case for other
> > Views too, but at least QTableView doesn't have this limitation. I don't
> > need a separate reference to the model.
> >
> > It also shouldn't be necessary to hold a separate reference to the
> > model, as QTreeView should have one internal reference to it.
> The extra reference is by virtue of tree being the parent of the model, rather 
> than the call to setModel(). What is SomeTreeModel() derived from?

It's derived from QAbstractItemModel, but I forgot to call
QAbstractItemModels' __init__ with the parent. Sorry for the noise.

BTW: Do you have any idea why I can't call model() right after
setModel()? I get a None object back. It works when I do have a global
reference to the model, but not if I create the Model right inside the
setModel call.


Your step will soil many countries.

More information about the PyQt mailing list