4
Qt实现信号灯_五个板栗的技术博客_51CTO博客
source link: https://blog.51cto.com/u_15515702/5937011
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Qt实现信号灯
精选 原创//设置背景颜色,椭圆弧度
ui->radioButton->setStyleSheet("QRadioButton::indicator{width:35px;height:35px;border-radius:17px}"
"QRadioButton::indicator:checked{background-color:green;}"
"QRadioButton::indicator:unchecked{background-color:red;}");
ui->radioButton->setStyleSheet("QRadioButton::indicator{width:35px;height:35px;border-radius:17px}"
"QRadioButton::indicator:checked{background-color:green;}"
"QRadioButton::indicator:unchecked{background-color:red;}");
QVBoxLayout *vbox = new QVBoxLayout(this);
TrafficLightWidget *widget = new TrafficLightWidget();
vbox->addWidget(widget);
vbox->setMargin(0);
QStateMachine *machine = new QStateMachine(this);
QState *redGoingYellow = createLightState(widget->redLight(), 3000);
redGoingYellow->setObjectName("redGoingYellow");
QState *yellowGoingGreen = createLightState(widget->yellowLight(), 1000);
yellowGoingGreen->setObjectName("yellowGoingGreen");
redGoingYellow->addTransition(redGoingYellow, SIGNAL(finished()), yellowGoingGreen);
QState *greenGoingYellow = createLightState(widget->greenLight(), 3000);
greenGoingYellow->setObjectName("greenGoingYellow");
yellowGoingGreen->addTransition(yellowGoingGreen, SIGNAL(finished()), greenGoingYellow);
QState *yellowGoingRed = createLightState(widget->yellowLight(), 1000);
yellowGoingRed->setObjectName("yellowGoingRed");
greenGoingYellow->addTransition(greenGoingYellow, SIGNAL(finished()), yellowGoingRed);
yellowGoingRed->addTransition(yellowGoingRed, SIGNAL(finished()), redGoingYellow);
machine->addState(redGoingYellow);
machine->addState(yellowGoingGreen);
machine->addState(greenGoingYellow);
machine->addState(yellowGoingRed);
machine->setInitialState(redGoingYellow);
machine->start();
TrafficLightWidget *widget = new TrafficLightWidget();
vbox->addWidget(widget);
vbox->setMargin(0);
QStateMachine *machine = new QStateMachine(this);
QState *redGoingYellow = createLightState(widget->redLight(), 3000);
redGoingYellow->setObjectName("redGoingYellow");
QState *yellowGoingGreen = createLightState(widget->yellowLight(), 1000);
yellowGoingGreen->setObjectName("yellowGoingGreen");
redGoingYellow->addTransition(redGoingYellow, SIGNAL(finished()), yellowGoingGreen);
QState *greenGoingYellow = createLightState(widget->greenLight(), 3000);
greenGoingYellow->setObjectName("greenGoingYellow");
yellowGoingGreen->addTransition(yellowGoingGreen, SIGNAL(finished()), greenGoingYellow);
QState *yellowGoingRed = createLightState(widget->yellowLight(), 1000);
yellowGoingRed->setObjectName("yellowGoingRed");
greenGoingYellow->addTransition(greenGoingYellow, SIGNAL(finished()), yellowGoingRed);
yellowGoingRed->addTransition(yellowGoingRed, SIGNAL(finished()), redGoingYellow);
machine->addState(redGoingYellow);
machine->addState(yellowGoingGreen);
machine->addState(greenGoingYellow);
machine->addState(yellowGoingRed);
machine->setInitialState(redGoingYellow);
machine->start();
- 赞
- 收藏
- 评论
- 分享
- 举报
上一篇:QT实现动态曲线
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK