[PyKDE] subclassing in pyqt

David Berner berner at ics.uci.edu
Sat Dec 23 01:05:38 GMT 2000


i found a problem while subclassing pyqt-classes in python.

e.g.

>>> class Mylistview(QListView):
>>>   (...)
>>>
>>> class Mylistitem(QListViewItem):
>>>   def __init__(self, parent, name, myvar):
>>>     apply(QListViewItem.__init__,(self,parent,name)
>>>     self.MyVar = myvar
>>>     (...)
>>>
>>> a = Mylistview(parent)
>>> Mylistitem(a, "first item", 5)

the problem is, when i call a method of Mylistview which returns an item
like:

>>> x = a.selectedItem()

since type(x) is not Mylistitem but QListViewItem, i can not access MyVar:

>>> print x.MyVar
>>> (...) AttributeError: MyVar

AFAIK there are no type-conversions in python (in C a simple cast would do),
so i see no way to solve this.

all comments are welcome,
David





More information about the PyQt mailing list