[PyQt] Re: problem with QAbstractItemModel
uvemas at gmail.com
Sat Nov 7 07:40:04 GMT 2009
On 2009-11-06 Baz Walter <bazwal at ftml.net> said:
> your implementation of QAbstractItemModel.index is going to get called
> *a lot* and in many unforseen ways.
Yes, but it is a general fact, not something that happens to my particular
> i think a more sane implementation
> would be something like this:
> def index(self, row, column, parent):
> if self.hasIndex(row, column, parent):
> branch = self.nodeFromIndex(parent)
> return self.createIndex(row, column, branch.childAtRow(row))
> return QModelIndex()
> this fixes your immediate bug, and will probably avoid many others.
I know that my implementation is very rough, but it is intended just for
testing purposes. Of course your workaround and other similar (like the one
sent by Linos) fixes the problem, but they leave the main question unanswered:
why wrong row values are passed to the index method? Is it expected? If it is
developers are forced to include good sanity code in their index method
implementation (as you and Linos did), but I've not seen any reference to this
in the Qt documentation. IMHO the Qt model implementation should not allow
wrong row values to be passed to the index method. In fact, the example in the
'Editable Tree Model Example' section of the Qt documentation doesn't check at
all the validity of the row argument passed to the index method
On the other hand the fact that my script works fine with some Qt/PyQt versions
but fails with recent versions seems to indicate that there is a bug either in
the Qt implemention of models or in that PyQt versions.
PS: Baz, thanks for your code snippet
Share what you know, learn what you don't
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 198 bytes
Desc: This is a digitally signed message part.
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20091107/fbd1eff3/attachment.bin
More information about the PyQt