'm trying to figure out how to use my own custom signals in combination with QStateMachine. I started with a simple example from here. Now I'm trying to create a new signal mysignal
and trigger a transition off of it. But I can't figure out how to structure the call to addtransition
, or how to use the SIGNAL("clicked()")
syntax to refer to mysignal
.
from PyQt4.QtGui import *
from PyQt4.QtCore import *
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
button = QPushButton()
machine = QStateMachine()
off = QState()
off.assignProperty(button, 'text', 'Off')
off.setObjectName('off')
on = QState()
on.setObjectName('on')
on.assignProperty(button, 'text', 'On')
mysignal = pyqtSignal()
off.addTransition(mysignal, on)
# Let's use the new style signals just for the kicks.
on.addTransition(button.clicked, off)
machine.addState(off)
machine.addState(on)
machine.setInitialState(off)
machine.start()
mysignal.emit()
button.resize(100, 50)
button.show()
sys.exit(app.exec_())