标签:games div ref retf nis tar star string stop
今天参与了代码编写,编写了奖品代码,即设置奖品等内容,编写很艰难,学习了很多东西,代码如下
#include "setwidget.h"
#include<QHBoxLayout>
#include<QVBoxLayout>
#include<QMessageBox>
#include<QTime>
#include<QDebug>
SetWidget::SetWidget(QWidget *parent) : QWidget(parent)
{
qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));//产生随机种子
this->setFixedSize(400,500);
//设置按钮
this->Oksetbutton=new QPushButton("确定设置");
this->Oksetbutton->setFixedSize(60,50);
this->retbutton=new QPushButton("返回上级");
this->retbutton->setFixedSize(60,50);
auto Hlayout=new QHBoxLayout;
Hlayout->addWidget(retbutton);
Hlayout->addWidget(Oksetbutton);
//设置一二三等奖的显示和布局
this->Label1=new PrizeLabel;
Label1->prizeHint.setText("一等奖");
this->Label2=new PrizeLabel;
Label2->prizeHint.setText("二等奖");
this->Label3=new PrizeLabel;
Label3->prizeHint.setText("三等奖");
//设置满足金额限制
auto widget=new QWidget;
widget->setFixedSize(200,60);
QLabel *widgethint=new QLabel("满足最低金额:");
widgetedit=new QLineEdit;
QHBoxLayout *widgetlayout=new QHBoxLayout;
widgetlayout->addWidget(widgethint);
widgetlayout->addWidget(widgetedit);
widget->setLayout(widgetlayout);
auto Vlayout=new QVBoxLayout;
Vlayout->addWidget(Label1);
Vlayout->addWidget(Label2);
Vlayout->addWidget(Label3);
Vlayout->addWidget(widget);
Vlayout->addLayout(Hlayout);
this->setLayout(Vlayout);
this->movie=new QMovie(":/new/prefix1/01.gif");
this->movlabel=new QLabel;
this->movlabel->setFixedSize(739,357);
this->movlabel->setFrameShape(QFrame::NoFrame);
this->movlabel->setMovie(movie);
connect(retbutton,&QPushButton::clicked,[this](){
emit retturnSig();//发出信号
});
connect(Oksetbutton,&QPushButton::clicked,[this](){
//获取到编辑框的值
Label1str=this->Label1->GetWinningprize();
Label1value=this->Label1->GetWinningodds();
Label2str=this->Label2->GetWinningprize();
Label2value=this->Label2->GetWinningodds();
Label3str=this->Label3->GetWinningprize();
Label3value=this->Label3->GetWinningodds();
//如果机率设置不合法
if((Label1value+Label2value+Label3value)!=100||(Label1value+Label2value+Label3value)>100){
QMessageBox::information(this,"错误提示","机率总和大于100或不等于100");
return;
}
this->swidget.show();
this->hide();
});
connect(&swidget,SIGNAL(startfinished()),this,SLOT(StartGames()));
//触发定时器
connect(&timer,&QTimer::timeout,[this](){
this->timer.stop();
this->movie->stop();
this->movlabel->hide();
qDebug()<<"随机数位:"<<randomnum;
//判断是谁获奖了 并显示信息
if(0<randomnum&&randomnum<=Label1value){
QMessageBox::information(this,QString("一等奖"),QString("奖品:%1").arg(Label1str));
}else if(Label1value<=randomnum&&randomnum<=(Label1value+Label2value)){
QMessageBox::information(this,QString("二等奖"),QString("奖品:%1").arg(Label2str));
}else if((Label1value+Label2value)<=randomnum&&randomnum<=(Label1value+Label2value+Label3value)){
QMessageBox::information(this,QString("三等奖"),QString("奖品:%1").arg(Label3str));
}
});
connect(&swidget,&startwidget::retfinished,[this](){
this->show();
});
}
//开始抽奖逻辑
void SetWidget::StartGames()
{
//随机产生个1-100的数值
randomnum=qrand()%100+1; //每次开始随机产生一个1-100的数值
this->timer.start(3000);//三秒开始定时器
//播放抽奖GIF
this->movlabel->show();
this->movie->start();
this->hide();
//qDebug()<<"str:"<<Labelstr<<" value:"<<Labelvalue;
}
第五日
标签:games div ref retf nis tar star string stop
原文地址:https://www.cnblogs.com/wmq123/p/9984507.html