[PyQt] Connecting to base class signals in subclass

Russell Valentine russ at coldstonelabs.org
Sat Mar 20 08:32:58 GMT 2010


On 03/19/10 18:45, Demetrius Cassidy wrote:
> 
> I am not sure if this is the intended behavior, but if I subclass a QWidget
> instance, and then try to connect to one of those signals in my subclass, I
> get a TypeError:
> 
>>>> class MyLabel(QtGui.QLabel):
> ...     def __init__(self):
> ...             self.linkActivated.connect(self._lnkActivated)
> ...
> ...     def _lnkActivated(self, link):
> ...             pass
> ...
>>>> l = MyLabel()
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "<stdin>", line 3, in __init__
> TypeError: pyqtSignal must be bound to a QObject, not 'MyLabel'
>>>>
> 
> Why can't I connect to my base class's signals in my subclass? 



You need to call the parent's init.
super(QtGui.QLabel, self).__init__()



More information about the PyQt mailing list