Skip to content

Instantly share code, notes, and snippets.

@cpascual
Last active May 5, 2016 09:09
Show Gist options
  • Save cpascual/bcf16fc1820680ef768fb7962473d24b to your computer and use it in GitHub Desktop.
Save cpascual/bcf16fc1820680ef768fb7962473d24b to your computer and use it in GitHub Desktop.
from PyQt4 import Qt
class Signaller(Qt.QObject):
signal = Qt.pyqtSignal()
class Base(object):
"""Base is not a QObject but provides a pyqtSignal signal member via
a Signaller hidden behind a property"""
def __init__(self):
self._signaller = Signaller()
@property
def signal(self):
return self._signaller.signal
class MyWidget(Qt.QLabel, Base):
"""3rd party widget which expects "signal" to be provided by Base"""
def __init__(self):
Qt.QLabel.__init__(self, 'testing signal')
Base.__init__(self)
# self.signal can now be used as expected
self.signal.connect(self.onSignal)
self.signal.emit()
def onSignal(self):
print "got signal!!!"
app=Qt.QApplication([])
w = MyWidget()
w.show()
app.exec_()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment