[PyQt] Overriding QStandardItem with __iter__ in PyQt5

triccare triccare triccare at gmail.com
Tue Oct 25 16:15:28 BST 2016


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.

Other environment info:

   - OS X 10.11.6
   - anaconda 1.5.1
   - Python 2.7.12
   - QT/PyQT5 versions: 5.6

Thank you for your time,
t.

from PyQt5 import (Qt, QtCore, QtGui, QtWidgets)
from sip import SIP_VERSION
import sys

print('QT Version="{}"'.format(QtCore.QT_VERSION_STR))
print('PYQT Version="{}"'.format(Qt.PYQT_VERSION_STR))
print('sip Version="{}"'.format(SIP_VERSION))


class LayerItem(QtGui.QStandardItem):

    def __iter__(self):
        for row in range(self.rowCount()):
            yield self.child(row)


app = QtWidgets.QApplication([])

model = QtGui.QStandardItemModel()
li = LayerItem('Layer Item')
print('li text="{}"'.format(li.text()))
model.appendRow(li)
model.appendRow(QtGui.QStandardItem('Standard Item'))


tree = QtWidgets.QTreeView()
tree.setModel(model)

tree.show()

sys.exit(app.exec_())
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20161025/002c8e62/attachment.html>


More information about the PyQt mailing list