Subclasses of QListViewItems: Re: [Fwd: Re: [PyKDE] Typecasting]

Boudewijn Rempt bsarempt at rempt.xs4all.nl
Wed Nov 15 21:36:49 GMT 2000


I've been experimenting with QListView - and I don't really understand my
findings. If you look at the attached code, you see that the same signal
fits one function, but not the other, even though they have the same
number of arguments.

Actually, all commented out connections gave an error like:

Traceback (most recent call last):
  File "qlsv_sig.py", line 77, in ?
    main()
  File "qlsv_sig.py", line 71, in main
    toplevel=frmListView()
  File "qlsv_sig.py", line 39, in __init__
    self.connect(self, SIGNAL("onItem(QListViewItem*)"), self.slotOneArg)
RuntimeError: Signal has wrong argument types for slot

And when I arrived at ...SIGNAL("mouseButtonClicked")... (line 53), I got
another error as well:

bash-2.03$ python qlsv_sig.py
QObject::connect: No such signal QObject::onViewport()
QObject::connect:  (sender name:   'unnamed')
QObject::connect:  (receiver name: 'unnamed')
QObject::connect: No such signal QObject::selectionChanged()
QObject::connect:  (sender name:   'unnamed')
QObject::connect:  (receiver name: 'unnamed')
Traceback (most recent call last):
  File "qlsv_sig.py", line 83, in ?
    main()
  File "qlsv_sig.py", line 77, in main
    toplevel=frmListView()
  File "qlsv_sig.py", line 53, in __init__
    self.connect(self, SIGNAL("mouseButtonClicked(int, QListViewItem*,
constQPoint&, int)"), self.slotFourArg)
RuntimeError: Signal has wrong argument types for slot

I'm using Qt 2.2.2, PyQt 2.2 and Python 2.0.

-------------- next part --------------
#!/usr/bin/env python

import os
import sys

from qt import *

class myListViewItem(QListViewItem):

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

  def slotHook(self):
    print "slotHook"

class frmListView(QListView):
  def __init__(self, parent=None):
    QListView.__init__(self, parent)

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

    self.rows=[]
    lvi=myListViewItem(self)

    lvi.setText(0, "xxxxx")
    lvi.setText(1, "yyyyy")
    self.rows.append(lvi)

    #self.connect(self, SIGNAL("clicked ( QListviewItem * )"), self.slotOneArg)
    self.connect(self, SIGNAL("collapsed ( QListViewItem * )"), self.slotOneArg)
    #self.connect(self, SIGNAL("currentChanged?(?QListViewItem?*?)"), self.slotOneArg)
    #
    # Note: the first doesn't work; the second does!
    #
    #self.connect(self, SIGNAL("doubleClicked?(?QListViewItem?*?)"), self.slotOneArg)
    self.connect(self, SIGNAL("doubleClicked ( QListViewItem * )"), self.slotOpenFile) 
    #self.connect(self, SIGNAL("expanded?(?QListViewItem?*?)?"), self.slotOneArg)
    #self.connect(self, SIGNAL("onItem?(?QListViewItem?*?)?"), self.slotOneArg)    
    #self.connect(self, SIGNAL("pressed?(?QListViewItem?*?)?"), self.slotOneArg)
    #self.connect(self, SIGNAL("returnPressed?(?QListViewItem?*?)"), self.slotOneArg)
    #self.connect(self, SIGNAL("selectionChanged?(?QListViewItem?*?)"), self.slotOneArg)
    

    self.connect(self, SIGNAL("onViewport?()"), self.slotNoArg)    
    self.connect(self, SIGNAL("selectionChanged?()"), self.slotNoArg)
    
    #self.connect(self, SIGNAL("pressed?(?QListViewItem?*, const?QPoint?&, int?)"), self.slotThreeArg)
    #self.connect(self, SIGNAL("rightButtonClicked?(?QListViewItem?*, const?QPoint?&, int?)"), self.slotThreeArg)
    #self.connect(self, SIGNAL("rightButtonPressed?(?QListViewItem?*, const?QPoint?&, int?)"), self.slotThreeArg)
    #self.connect(self, SIGNAL("clicked?(?QListViewItem?*, const?QPoint?&, int?)"), self.slotThreeArg)
    
    #self.connect(self, SIGNAL("mouseButtonClicked?(?int, QListViewItem?*, const?QPoint?&, int?)"), self.slotFourArg)
    #self.connect(self, SIGNAL("mouseButtonPressed?(?int, QListViewItem?*, const?QPoint?&, int?)"), self.slotFourArg)



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

  def slotOneArg(self, item):
    print item

  def slotNoArg(self):
    print "No args"
    
  def slotThreeArg(self, item, point, col):
    print item, point, col

  def slotFourArg(self, button, item, point, col):
    print button, item, point, col
    
def main():

  qapp=QApplication(sys.argv)
  toplevel=frmListView()
  toplevel.show()
  qapp.connect(qapp, SIGNAL('lastWindowClosed()'), qapp, SLOT('quit()'))
  print qapp.exec_loop()
  
if __name__=="__main__":
  main()


More information about the PyQt mailing list