[PyQt] Looking for complex tree view example

Aaron Digulla digulla at hepe.com
Fri Apr 18 08:29:23 BST 2008

Quoting David Boddie <david at boddie.org.uk>:

> You could port the C++ Editable Tree Model example from the Qt package,
> but that might not be dynamic enough for your purposes.
> Another example of the model/view classes in Python is the PyPI Browser
> application I started writing almost two years ago(!):
>   http://pypi.python.org/pypi/PyPI-Browser/1.5

I'll have a look at both.

> There should be lots of other complex models out there written in Python,
> especially in the scientific computing and visualisation domain.

"Should" is the keyword here. Googling for "pyqt QAbstractItemModel  
class def __init__" yields 4 pages of results of which three are  
relevant. koders.com returns 16 examples.

I feel that this is a no-go area: There is little information how to  
create a real-world tree model with more than one column and it seems  
that few people have dared to venture into this. Those examples that  
do exist are very limited. They either just display data or allow  
inline editing. I just found a single example which allows to move  
nodes around, I've never seen drag'n'drop node moving anywhere.

Okay, I feel I need to vent some frustration. Take the following with  
a grain of salt and remember that someone who criticizes you cares  
about you.

My own experiments with the tree model resulted in a lot of spurious  
crashes because of memory issues. I'd really prefer if the PyQt  
developers would stop insisting that I have to get the memory model  
right or my application will crash. I mean, even if I make a mistake  
in my code, it *might* run for a while and then suddenly crash at a  
completely different place! That's not the "Python way". That's  
exactly why I stopped using C/C++ ten years ago.

I mean, I'm a seasoned programmer, I've written my own OS and text  
editor, I understand how memory allocation works and how it plays with  
virtual memory, I've written libraries which can be used from Python,  
etc. and even I can't get it right with PyQt! Don't take this as an  
insult but for me, it feels that PyQt is *designed* to make it easier  
to produce buggy code than stable code. Just look at the amount of  
mails on this list with people who have memory issues!

And what bugs me most is that many of these issues could be prevented  
with just small changes in the PyQt layer (like saving a pointer to  
the model when you call setModel()). It feels like PyQt is 95% good,  
so the bad 5% hurt even more because it almost perfect!

If all else fails, there should at least be a "safe net" version of  
PyQt which tracks all Qt objects created and prints warnings with  
stack traces when they leak or might be deleted before both sides are  
done with them.

It would also help if PyQt could print complete stack traces like when  
a python callback is invoked from Qt like in Python (A) -> Qt ->  
Python (B): The stack trace will only show the B portion, so I have no  
idea what A might be.


Aaron "Optimizer" Digulla a.k.a. Philmann Dark
"It's not the universe that's limited, it's our imagination.
Follow me and I'll show you something beyond the limits."

More information about the PyQt mailing list