[PyKDE] QListView(Item) subclass insertItem strange behaviour, bug?

marvelan L marvelan at hotmail.com
Sat Jan 4 19:03:01 GMT 2003

Hi list

I have subclassed QListView and QListViewItem in order to be able
to use my own list view items with additional methods.

I need to call these methods when a list view item is inserted as a
child to another item. But it does not seem to be possible, read on :-)

My problem is that when insertItem of a QListViewItem or QListView is
called, the object passed to it is a QListViewItem and not my subclass
that I'm using.

I made a small test program to demonstrate. When I run the code below
it prints the following:

List class: 'qt.QListViewItem'
Item class: 'qt.QListViewItem'

It should print something like:

List class: 'MyList'
Item class: 'MyItem'

The problem is that I need to access my own added methods in MyList when
insertItem is called. But it seems that it is called with a object of the
base class and not my specialisation class MyList.

As you can see in the code below I'm not using QListViewItem but instead my
own MyItem, but still insertItem is called with QListViewItem and not

Seems like a bug in PyQt (or Qt?) to me, or am I missing something?

Versions: PyQt 3.4, Python 2.2.1, Qt 3.4
All compiled with gcc version 2.95.3


from qt import *
import sys

class MyItem(QListViewItem):

    def __init__(self, parent, label):
        QListViewItem.__init__(self, parent, label)

    def insertItem(self, item):
        print "Item class: '%s'" % item.__class__
        QListViewItem.insertItem(self, item)

class MyList(QListView):

    def __init__(self, parent=None, name=None, fl=0):
        QListView.__init__(self,parent,name, fl)
        self.addColumn("Column 1")

    def insertItem(self, item):
        print "List class: '%s'" % item.__class__
        QListView.insertItem(self, item)

app = QApplication(sys.argv)
main = QMainWindow()

list = MyList(main)
item1 = MyItem(list, "item1")
item2 = MyItem(item1, "item2")



The new MSN 8: smart spam protection and 2 months FREE*  

More information about the PyQt mailing list