I have a question to using the QStateMachine
-System of PyQt5
properly.
Using
State.assignProperty(aLineEdit, "plainText", "Some text")
allows to set "Some text"
to the plainText
-property whenever aState
is active.
Question: What if "Some text"
is not constant or known before execution? My intention is to pass a function (not unlike connecting a partial
or lambda
expression to an event) instead of a value that would yield the appropriate value when the state is entered.
My only idea to emulate this behavior is to connect a function that sets the property to aState.entered
. However I'm not happy with that solution because it mixes up the places where properties are set and a reason to use the QStateMachine
is to avoid having to manually set states yourself.
Your only idea is correct, but you should factor it out into a helper method so that the function is invoked at the time the state is entered.