[PyQt] Overriding QStandardItem with __iter__ in PyQt5

triccare triccare triccare at gmail.com
Tue Oct 25 19:38:35 BST 2016


On Tue, Oct 25, 2016 at 11:15 AM, triccare triccare <triccare at gmail.com>
wrote:

> This is quite interesting... If you add a traceback.print_stack()
> here:
>
> >     def __iter__(self):
> >         for row in range(self.rowCount()):
> >             yield self.child(row)
>
> It seems like it gets called when doing model.appendRow(li).
>
> Looking at Qt's documentation, QStandardItemModel::appendRow can be
> called with a QStandardItem, or a list of QStandardItems. I'm guessing
> since your custom class implements __iter__, it's treated like a list
> of QStandardItems (because how would PyQt know the difference
> otherwise?)
>
> Florian
>

Hmmm, if PyQt4 looked specifically for a QList or type(list), but now PyQt5
just looks for "list-like", that could be the explanation. Hard to tell
where the check would be in the interface between python and C.

Cleverness foiled by others' cleverness.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20161025/9934318c/attachment-0001.html>


More information about the PyQt mailing list