[Fwd: Re: [PyKDE] Typecasting]
Mark Kimsal
chugadie.geo at yahoo.com
Tue Nov 14 23:08:21 GMT 2000
-------- Original Message --------
Subject: Re: [PyKDE] Typecasting
Date: Mon, 13 Nov 2000 10:18:18 -0500
From: mark kimsal <chugadie.geo at yahoo.com>
Reply-To: mark at tapinternet.com
To: pyqt <pykde at mats.gmd.de>
References: <3A0F54C2.9376C03C at kimsal.com>
I couldn't get your example to work. This was the error given
QObject::connect: No such signal
QObject::rightButtonClicked(QListViewItem*,constQPoint&,int)
QObject::connect: (sender name: 'unnamed')
QObject::connect: (receiver name: 'unnamed')
> 11.11.2000, 01:38, Mark Kimsal wrote:
>
> > Okay, i've been stuck all day on this problem.
>
> > I have a class that subclasses QListViewItem, FTPDirItem. I populate a
> > QListView with a few instances of FTPDirItem. When I connect the signal
> > from the containing QListView it requires a pointer to an object of type
> > QListViewItem. When I try to access object variables inside my SLOT
> > function I get AttributeErrors. type(myobj) reveals that the program
> > thinks the object is a QListViewItem at that point. I can access
> > user-defined object methods of FTPDirItem, but whenever I try to access
> > variables I created in the subclasses' __init__() method I get an
> > error. So my question is how can I typecast this object back into an
> > FTPDirItem inside my SLOT callback function?
>
> This works for me:
>
> import string, sys
> from qt import *
>
> class List(QListView):
> def __init__(self, *args):
> apply(QListView.__init__,(self,) + args)
> self.addColumn("A")
> self.addColumn("B")
> self.itemList = []
> self.data = (['1','2'], ['11','12'],['2','3'])
> self.connect(self, SIGNAL("rightButtonClicked(QListViewItem *, const QPoint &, int)"), \
> self.rbClicked)
> self.addItems()
>
> def addItems(self):
> for row in self.data:
> item = TestItem(self)
> self.itemList.append(item)
> for i in range(len(row)):
> item.setText(i, row[i])
>
> def rbClicked(self, item, point, col):
> print item.subvar, item.text(0)
>
> class TestItem(QListViewItem):
> def __init__(self, parent):
> QListViewItem.__init__(self, parent)
> self.subvar = 'Test'
>
> a = QApplication(sys.argv)
> mw = List()
> a.setMainWidget(mw)
> mw.show()
> a.exec_loop()
>
> Per
More information about the PyQt
mailing list