[PyKDE] QAbstractItemView Question

Matt Chambers chambers at imageworks.com
Thu Nov 16 22:57:07 GMT 2006

Matt Newell wrote:
> On Thursday 16 November 2006 13:18, Brent Villalobos wrote:
>> I'm a PyQt newbie so maybe there's an easier way, but I wrote my own.  I
>> saved out various view attributes, swapped in a new model, and then set the
>> view to those saved-out variables.  It works well and to the end user the
>> table just updates without losing any context.  It's a little annoying to
>> code, but I was able to save out and set selections, sort order, vertical
>> positions, column size, and column positions.
>> The problem with selections is when a new model has a different number or
>> order of elements.  For example, if the first row is selected in your
>> current model, then you can easily set the first row as selected when you
>> reload the model.  However, the first row in the new model may be a
>> completely different element.  I worked around this by designating a unique
>> key for each row.  So instead of recording which rows are selected, I
>> recorded which keys were selected.  Then I had to search through the new
>> model and find those keys and select them in the selection model.
>> -Brent
>>> On 11/16/06, Matt Chambers <chambers at imageworks.com> wrote:
>>>> Is it possible that using one of the View classes, to reset() the model,
>>>> but still maintain any selections the users had on items that were in
>>>> the old data, and the new data?
> Why not just avoid calling reset?  If you use beginInsertRows, layoutChanged, 
> or whatever is needed, then the selection will be maintained automatically.
> Matt
Well, every row is updated every refresh, so it seemed easier.  It is 
easier, if you don't take into account
all the state data gets blown away.  I just wrote models to sit on top 
of self updating objects I was already using.
They don't know a model is watching them.  Seems like my data will have 
to know a lot about the model
for this way to work properly, or I have to move all the updating into 
the model.  I suppose then you loop
through your new data, updating, adding, and removing data?  My datasets 
can easily have thousands of rows. 
Has anyone done this and not lost GUI interactiveness?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20061117/318e0fee/attachment.html

More information about the PyQt mailing list