gpt4 book ai didi

c++ - 布局中的 Qt 状态机转换

转载 作者:可可西里 更新时间:2023-11-01 16:21:26 24 4
gpt4 key购买 nike

嗯,我正在开发一个 Qt 应用程序,我想使用 Qt State Framework 制作一些动画。

首先:如何通过使用状态转换将水平布局中包含的一组按钮设置为另一个垂直布局的动画?

第二:处于状态时如何显示小部件?例如菜单:当用户单击菜单中的按钮时,将显示小部件(之前已使用 widget->hide() 隐藏)...???

这是一个代码示例:

boxInsert = new BoxInsert(this);
boxInsert->hide ();


btn1 = new QPushButton("Introducir", this);
btn2 = new QPushButton("Informe", this);
btn3 = new QPushButton("Salir", this);

QStateMachine *machine = new QStateMachine(this);

QState *st1 = new QState(machine);
st1->setObjectName ("menuMode");
st1->assignProperty (btn1, "pos", QPointF(center - btn1->width () / 2, 20));
st1->assignProperty (btn2, "pos", QPointF(center - btn1->width () / 2, 40));
st1->assignProperty (btn3, "pos", QPointF(center - btn1->width () / 2, 60));
st1->assignProperty (boxInsert, "visible", QVariant(false));

QState *st2 = new QState(machine);
st2->setObjectName ("barMode");
st2->assignProperty (btn1, "pos", QPointF(40, 0));
st2->assignProperty (btn2, "pos", QPointF(40, 0));
st2->assignProperty (btn3, "pos", QPointF(40, 0));
st1->assignProperty (boxInsert, "visible", QVariant(true));

machine->setInitialState (st1);

QAbstractTransition *t1 = st1->addTransition (btn1, SIGNAL(clicked()), st2);
//QSequentialAnimationGroup *sq1 = new QSequentialAnimationGroup;
//sq1->addPause (250);
t1->addAnimation (new QPropertyAnimation(btn1, "pos"));
t1->addAnimation (new QPropertyAnimation(btn2, "pos"));
t1->addAnimation (new QPropertyAnimation(btn3, "pos"));
t1->addAnimation (new QPropertyAnimation(boxInsert, "visible"));

machine->start ();

最佳答案

这就像当您启动机器时它会改变按钮的颜色,这可能表明它已被单击,然后执行与您的信号链接的操作,以便执行其链接的插槽。

s0->addTransition(s1);
s1->assignProperty(ui->pushButton,"styleSheet","background-color:rgb(255,0,0);");
s1->addTransition(s2);
s2->addTransition(ui->pushButton,SIGNAL(clicked()),s0);
QStateMachine m;
m.addState(s0);
m.addState(s1);
m.addState(s2);
m.setInitialState(s0);

要使小部件可见,请添加如下状态转换:

s1->assignProperty(MyWid,"visible", true);

并在状态 s1 的 s0 中添加转换。

关于c++ - 布局中的 Qt 状态机转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18860551/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com