[PyQt] Overriding QStandardItem with __iter__ in PyQt5
Florian Bruhin
me at the-compiler.org
Tue Oct 25 16:38:43 BST 2016
Hey,
* triccare triccare <triccare at gmail.com> [2016-10-25 11:15:28 -0400]:
> Greetings,
>
> Below is the code in question. Basically, I am adding an __iter__ property
> to QStandardItem. In PyQt4, this worked fine. However, in PyQt5, the text
> of the item no longer appears in the QTreeView. The item is there; you can
> select it. It just doesn't show.
>
> PyQt5.QtGui.QStandardItem does not appear to natively have an __iter__
> property, so not sure why this is having such an effect.
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
--
http://www.the-compiler.org | me at the-compiler.org (Mail/XMPP)
GPG: 916E B0C8 FD55 A072 | http://the-compiler.org/pubkey.asc
I love long mails! | http://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20161025/cd8753f4/attachment.sig>
More information about the PyQt
mailing list