[PyKDE] subclassing QListViewItem

Phil Thompson phil at riverbankcomputing.co.uk
Mon Oct 27 18:52:00 GMT 2003


On Monday 27 October 2003 5:24 pm, Peter Bienstman wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi all,
>
> The following code works as expected:
>
> QListViewItem(self.element_list, "foo")
>
> But now I'm trying to subclass a QListViewItem:
>
> class ElementItem(QListViewItem):
>     def __init__(self,  parent, elem):
>         QListViewItem.__init__(parent, "foo")  # line x
> 	...
>
> If I try this:
>
> ElementItem(self.element_list, elem)
>
> I get:
>
> line x: TypeError: unbound method __init__() must be called with
> QListViewItem instance as first argument (got QListView instance instead)
>
> But I was able to give it a QListView as first constructor argument when I
> created the ListViewItems directly.
>
> Am I missing something?

The error message you are getting describes exactly what is wrong.

Pass "self" to QListViewItem.__init__().

Phil




More information about the PyQt mailing list