[PyKDE] parent method of QObject

Boudewijn Rempt bsarempt at rempt.xs4all.nl
Thu Feb 24 09:20:57 GMT 2000


Looks a bit like the problem I had with version 0.10: if I subclass
a QListViewItem, then add that QListViewItem to a QListView, every
time I ask my QListView for my subclassed QListViewItem, I get 
a QListViewItem:

#!/usr/bin/env python

import os
import sys

from qt import *
from kdecore import *
from kdeui import *

TRUE=1
FALSE=0

class myListViewItem(QListViewItem):

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

  def slotHook(self):
    print "slotHook"

class frmListView(QListView):
  """
    Self-displaying view of database data.
  """
  def __init__(self, parent):
    QListView.__init__(self, parent)

    self.addColumn("a", 200)
    self.addColumn("b", 200)

    self.rows=[]
    lvi=myListViewItem(self)
    print lvi
    lvi.setText(0, "xxxxx")
    lvi.setText(1, "yyyyy")
    self.rows.append(lvi)

    self.connect(self, SIGNAL("doubleClicked ( QListViewItem * )")
                     , self.slotOpenFile
                     )

  def slotOpenFile(self, item):
    print item
    self.currentItem().slotHook()

class kuraView(frmListView):
  def __init__(self, parent, name):
    self.parent=parent
    self.name=name

    frmListView.__init__( self
                        , parent=self.parent
                        )
class kuraApp(KTMainWindow):

  def __init__(self, app=None, *args):
    apply(KTMainWindow.__init__,(self,) + args)
    self.app=app
    self.initView()

  def initView(self):
    self.view = kuraView(self, "kura")
    self.setView(self.view)
    self.view.show()

def main(argv):
  app=KApplication(sys.argv, "my")
  my=kuraApp()
  my.show()
  return app.exec_loop()

if __name__=="__main__":
  main(sys.argv)


Running and then doubleclicking gives this:

bash-2.03$ python inherit.py 
<__main__.myListViewItem instance at 817c8a8>
<qt.QListViewItem instance at 817a070>
Traceback (innermost last):
  File "inherit.py", line 47, in slotOpenFile
    self.currentItem().slotHook()
AttributeError: slotHook






More information about the PyQt mailing list