1

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.

ekhumoro
  • 115,249
  • 20
  • 229
  • 336
  • 1
    Wouldn't a dynamic property undermine the logic of the state-machine? If a property can be either `A` or `B`, then that would seem to imply two different states. – ekhumoro Jan 10 '17 at 16:47
  • @ekhumoro One could say that I now how the state of the property is defined (expressed for example by a method) when the respective machine state is active. Anyway, I just hope(d) that there is a way to use the state machine in a more flexible way. –  Jan 10 '17 at 21:16
  • The flexibility is provided by the `enter` and `exit` signals. – ekhumoro Jan 10 '17 at 21:46

1 Answers1

0

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.

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313