[PyKDE] Static member functions

Phil Thompson phil at riverbankcomputing.co.uk
Wed Dec 15 09:15:32 GMT 2004


>
> Followup: I seem to have found sender(), but I get the usual 'you can't
> do this because it was not created in python' error.
>
> So I still don't know how to go about it. Here's a sample class that I
> just typed up:
>
> class testDlg:
> 	def __init__(self):
> 		self.dlg=QWidgetFactory.create('lineedit.ui') #just a
> dialog with 2 lineedit boxes named lineedit1 and lineedit2, clicking
> between them should print out different instances
> 		self.dlg.connect(self.dlg.child('lineedit1'),
> SIGNAL('lostFocus()'), self.lostFocus)
>
> 	def lostFocus(self):
> 		print self.dlg.sender() # error here
>
> 	def show(self):
> 		self.dlg.show()
> if __name__=='__main__':
> 	d=testDlg()
> 	d.show()
> 	qApp.exec_loop()

Like I said, the slot must be a member of a QObject derived class. Also,
sender() should be from the receiver - there's no point in asking the
sender who the sender is :)

So, testDlg should sub-class from QObject and the lostFocus() method
should be...

    def lostFocus(self):
        print self.sender()

Phil




More information about the PyQt mailing list