[英]Is there a way to pass signal arguments through QStateMachine QState transitions?
For example, let's say I have some QButtonBucket
class containing some number N QPushButton
s within it, and I want pushing any of those buttons to cause a transition from some state to another.例如,假设我有一些
QButtonBucket
类,其中包含一些N QPushButton
s,并且我想要推动这些按钮中的任何一个以导致从某个状态转换到另一个状态。 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
但是,假设我想对导致转换的源
QPushButton
做一些事情,例如如果转换是从state_1
到state_2
改变它的颜色,或者如果转换是从state_3
回到state_1
可能禁用它
I want to handle this within the tight bounds of the QStateMachine
logic due to the asynchronous nature of QStateMachine
s.我想处理这个的紧密范围内
QStateMachine
逻辑由于异步特性QStateMachine
秒。 I don't want to have to track what button was clicked, or any other stateful data for that matter, within QButtonBucket
.我不想在
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.如果有一种方法可以获取与
addTransition
标识的信号一起传递的参数,并在进入新状态后对其进行操作,那将非常完美。 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?是否有一种众所周知的好方法来实现我想要完成的目标?
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.您可以使用
QState.assignProperty (self, QObject object, str name, QVariant value)
函数,该函数指示状态在进入状态时设置对象的属性。 So something like this could be done:所以可以做这样的事情:
state_1.assignProperty(button, "enabled", false)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.