[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: [PyQt] Overriding QStandardItem with __iter__ in PyQt5
From: triccare triccare <triccare () gmail ! com>
Date: 2016-10-25 18:38:35
Message-ID: CADtmbDCxGu--9HaTq+OS62CLe9krWkQcTP5NHA+g53rVpdv8Mw () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
On Tue, Oct 25, 2016 at 11:15 AM, triccare triccare <triccare@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.
[Attachment #5 (text/html)]
<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Oct 25, 2016 at 11:15 \
AM, triccare triccare <span dir="ltr"><<a href="mailto:triccare@gmail.com" \
target="_blank">triccare@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" \
style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div \
dir="ltr"><span style="font-size:12.8px">This is quite interesting... If you add a \
traceback.print_stack()</span><br style="font-size:12.8px"><span \
style="font-size:12.8px">here:</span><br style="font-size:12.8px"><br \
style="font-size:12.8px"><span style="font-size:12.8px">> def \
__iter__(self):</span><br style="font-size:12.8px"><span style="font-size:12.8px">> \
for row in range(self.rowCount()):</span><br style="font-size:12.8px"><span \
style="font-size:12.8px">> yield self.child(row)</span><br \
style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">It seems \
like it gets called when doing model.appendRow(li).</span><br style="font-size:12.8px"><br \
style="font-size:12.8px"><span style="font-size:12.8px">Looking at Qt's documentation, \
QStandardItemModel::appendRow can be</span><br style="font-size:12.8px"><span \
style="font-size:12.8px">called with a QStandardItem, or a list of QStandardItems. I'm \
guessing</span><br style="font-size:12.8px"><span style="font-size:12.8px">since your custom \
class implements __iter__, it's treated like a list</span><br \
style="font-size:12.8px"><span style="font-size:12.8px">of QStandardItems (because how would \
PyQt know the difference</span><br style="font-size:12.8px"><span \
style="font-size:12.8px">otherwise?)</span><br style="font-size:12.8px"><br \
style="font-size:12.8px"><span \
style="font-size:12.8px">Florian</span></div></blockquote><div><br></div><div>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.</div><div><br></div><div>Cleverness foiled by others' \
cleverness.</div></div></div></div>
[Attachment #6 (text/plain)]
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic