1

For example, let's say I have some QButtonBucket class containing some number N QPushButtons within it, and I want pushing any of those buttons to cause a transition from some state to another. This is simple enough:

for button in button_bucket.get_buttons():
    state_1.addTransition(button.clicked, state_2)

However, let's say I want to do something with the source QPushButton that causes the transition, such as changing its color if the transition is from state_1 to state_2, or maybe disabling it if the transition is from state_3 back to state_1

I want to handle this within the tight bounds of the QStateMachine logic due to the asynchronous nature of QStateMachines. I don't want to have to track what button was clicked, or any other stateful data for that matter, within QButtonBucket.

If there was a way to acquire arguments passed along with the signal identified in addTransition, and act on them after the new state is entered, that would be pretty much perfect. But I'm not seeing an easy solution to implement that.

Is there a known-good way of achieving what I'm trying to accomplish?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Connor Spangler
  • 805
  • 2
  • 12
  • 29

1 Answers1

0

You can use QState.assignProperty (self, QObject object, str name, QVariant value) function which instructs a state to set a property of an object when the state is entered. So something like this could be done:

state_1.assignProperty(button, "enabled", false)
Nejat
  • 31,784
  • 12
  • 106
  • 138
  • That's something I looked at, however as I said we're talking multiple buttons, where you need to know which button to apply styling to, and storing the identity of the source button externally from the state machine defeats its stateliness. – Connor Spangler Nov 05 '20 at 13:14