[PyQt] PyQt createIndex question

Andreas Pakulat apaku at gmx.de
Sun Sep 14 17:24:38 BST 2008


On 14.09.08 11:12:09, Doug Nichols wrote:
> The only thing I mean by this that the data I'm displaying as a tree is in a
> database that can and will be updated from multiple locations and will
> change frequently.  The tree view is alphabetized and so the 3 row may
> become the 5 row and so the index row value will frequently be
> outdated.

Thats where a proxy model that sorts for you comes in handy :)

>  In addition to this, the leaves of the tree are frequently associated
>  with multiple trunks.  Basically picture the leaf as a song and the
>  trunk as the artist.  Several songs have multiple artists and are
>  listed under all of them in the tree.  Therefore, I can't just assume
>  the first artist listed is always the artist of the song.  Therefore,
>  the initial solution I had was to store the artist item, the row the
>  artist was in, and the song in a tuple.  I would then check the
>  current row of the artist and compare it to the old row and if it was
>  different, then signal a layout change.  The same for the song row
>  which is already included in the index.  Not a perfect DB change
>  detection system, but would work for now.  Therefore, I would
>  probably store that tuple in the dictionary and retrieve it based on
>  the id in the internalptr of the index and clear the database
>  whenever I issue a layout change.

Aah, so in fact you don't have a tree-like structure yet at the
"backend" but just the database relations. I don't quite understand how
you'd get notified of DB changes, but yeah as soon as that happens and
if you can't figure out what exactly the change was - i.e. row
added/removed or just some text-change then you'll need layoutChanged
and eventually even reset. Note though that those are pretty expensive
things to signal, the view will invalidate all its internal state and
query all the data again.

Andreas

-- 
Good day for a change of scene.  Repaper the bedroom wall.


More information about the PyQt mailing list