赞
踩
通过在QT中对界面进行设计,使界面实现
1、登录/注册功能
2、点餐功能(显示图片、库存、点菜数量)
3、购物车界面(对已点的菜品进行总结,点了哪些菜品就显示哪些菜品的点菜数量)
- //主界面(登录界面)
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- #include "zuce.h"
- #include "diang.h"
- diang* food;
- MainWindow::MainWindow(QWidget *parent)
- : QMainWindow(parent)
- , ui(new Ui::MainWindow)
- {
- ui->setupUi(this);
- }
-
- MainWindow::~MainWindow()
- {
- delete ui;
- }
- //自定义槽
- void MainWindow::jian(QString data)
- {
- //存储账号和密码
- list<<data;
-
- }
-
- //登录
- void MainWindow::on_pushButton_clicked()
- {
- int info=0;
- static int num=3;
- QString data=ui->ledit1->text()+"#"+ui->ledit2->text();
- for(int i=0;i<list.size();i++)
- {
- if(data==list[i])
- {
- qDebug()<<"登录成功";
- QMessageBox::information(this,"", "登录成功");
- info=1;
- break;
- }
- }
- if(info==0)
- {
- //清空输入框
- ui->ledit1->clear();
- ui->ledit2->clear();
- qDebug()<<"登录失败";
- num--;
- QString tex="账号密码错误,你还剩"+QString::number(num)+"次机会";
- //qDebug()<<"你还剩"<<num<<"次机会";
- QMessageBox::information(this,"",tex);
- }
- //登录成功后的界面
- if(info==1)
- {
- //生成点餐界面
- food=new diang(nullptr);
- this->hide();
- food->show();
-
- }
- //次数用完就关闭
- if(num==0)
- this->close();
-
- }
- //注册
- void MainWindow::on_pushButton_2_clicked()
- {
- zuce* ZC=new zuce(this);
- this->hide();
- ZC->show();
- }
- //注册界面
- #include "zuce.h"
- #include "ui_zuce.h"
- #include "mainwindow.h"
- #include<QDebug>
- MainWindow* fu;
- zuce::zuce(QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::zuce)
- {
- ui->setupUi(this);
- //找到父界面
- QWidget* w=parentWidget();
- //转化类型
- fu = dynamic_cast<MainWindow*>(w);
- //连接信号和槽函数
- connect(this,&zuce::che,fu,&MainWindow::jian);
- }
-
- zuce::~zuce()
- {
- delete ui;
- }
-
- void zuce::on_pushButton_2_clicked()
- {
- this->hide();
- fu->show();
- }
-
- void zuce::on_pushButton_clicked()
- {
- QString word=ui->zuce1->text();//账号
- QString pass=ui->zuce2->text();//密码
- ui->zuce1->clear();
- ui->zuce2->clear();
- QString data=word+'#'+pass;
- lis<<data;
- for(int i=0;i<lis.size();i++)
- {
- qDebug()<<lis[i];
- }
- //发送信号
- emit che(data);
- }
- //点餐界面
- #include "diang.h"
- #include "ui_diang.h"
- #include "mainwindow.h"
- #include "cede.h"
- cede* cai;
- //菜名
- QString ming[12]={"麻辣窝窝头","黄金凤尾虾","糖果炒肉","福袋","好看的福袋","枫达","一人嘉禾","鸡你太莓","仰望星空","炸坤排","ikun工作餐","狱卒"};
- //数量
- int sum[12]={};
- //价格
- int much[12]={15,30,25,30,50,10,2,15,198,20,35,998};
- //原库存
- int yuan[12]={10,10,10,10,10,10,100,10,10,10,10,10};
- //库存
- int ku[12]={10,10,10,10,10,10,100,10,10,10,10,10};
- //总金额
- int erdu=0;
- diang::diang(QWidget *parent) :
- QWidget(parent),
- ui(new Ui::diang)
- {
- ui->setupUi(this);
- //库存
- ui->lab1_4->setText(QString::number(ku[0]));
- ui->lab2_4->setText(QString::number(ku[1]));
- ui->lab3_4->setText(QString::number(ku[2]));
- ui->lab4_4->setText(QString::number(ku[3]));
- ui->lab5_4->setText(QString::number(ku[4]));
- ui->lab6_4->setText(QString::number(ku[5]));
- ui->lab7_4->setText(QString::number(ku[6]));
- ui->lab8_4->setText(QString::number(ku[7]));
- ui->lab9_4->setText(QString::number(ku[8]));
- ui->lab10_4->setText(QString::number(ku[9]));
- ui->lab11_4->setText(QString::number(ku[10]));
- ui->lab12_4->setText(QString::number(ku[11]));
- //数量
- ui->lab1_5->setText(QString::number(sum[0]));
- ui->lab2_5->setText(QString::number(sum[1]));
- ui->lab3_5->setText(QString::number(sum[2]));
- ui->lab4_5->setText(QString::number(sum[3]));
- ui->lab5_5->setText(QString::number(sum[4]));
- ui->lab6_5->setText(QString::number(sum[5]));
- ui->lab7_5->setText(QString::number(sum[6]));
- ui->lab8_5->setText(QString::number(sum[7]));
- ui->lab9_5->setText(QString::number(sum[8]));
- ui->lab10_5->setText(QString::number(sum[9]));
- ui->lab11_5->setText(QString::number(sum[10]));
- ui->lab12_5->setText(QString::number(sum[11]));
- cai=new cede(this);
- cai->hide();
- //连接信号和槽
- connect(this,&diang::xinjian,cai,&cede::chuan);
- }
-
- diang::~diang()
- {
- delete ui;
- }
-
- void diang::on_pushButton_2_clicked()
- {
- QMessageBox::information(this,"","坤坤正在火热为你制作");
- }
- //1
-
- void diang::on_pushButton_3_clicked()
- {
- if(sum[0]==0)
- {
- QMessageBox::information(this,"","已经是最少的了");
- return;
- }
- else
- {
- sum[0]-=1;
- ku[0]+=1;
- erdu-=much[0];
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab1_5->setText(QString::number(sum[0]));
- ui->lab1_4->setText(QString::number(ku[0]));
- }
- }
-
- void diang::on_pushButton_4_clicked()
- {
- if(sum[0]==yuan[0])
- {
-
- QMessageBox::information(this,"","已经是所有库存了");
- return;
- }
- else
- {
- sum[0]+=1;
- ku[0]-=1;
- erdu+=much[0];
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab1_5->setText(QString::number(sum[0]));
- ui->lab1_4->setText(QString::number(ku[0]));
- }
- }
- //2
-
- void diang::on_pushButton_5_clicked()
- {
- if(sum[1]==0)
- {
- QMessageBox::information(this,"","已经是最少的了");
- return;
- }
- else
- {
- sum[1]-=1;
- ku[1]+=1;
- erdu-=much[1];
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab2_5->setText(QString::number(sum[1]));
- ui->lab2_4->setText(QString::number(ku[1]));
- }
- }
-
- void diang::on_pushButton_6_clicked()
- {
- if(sum[1]==yuan[1])
- {
-
- QMessageBox::information(this,"","已经是所有库存了");
- return;
- }
- else
- {
- sum[1]+=1;
- ku[1]-=1;
- erdu+=much[1];
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab2_5->setText(QString::number(sum[1]));
- ui->lab2_4->setText(QString::number(ku[1]));
- }
- }
- //3
-
- void diang::on_pushButton_11_clicked()
- {
- if(sum[2]==0)
- {
- QMessageBox::information(this,"","已经是最少的了");
- return;
- }
- else
- {
- sum[2]-=1;
- ku[2]+=1;
- erdu-=much[2];
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab3_5->setText(QString::number(sum[2]));
- ui->lab3_4->setText(QString::number(ku[2]));
- }
- }
-
- void diang::on_pushButton_21_clicked()
- {
- if(sum[2]==yuan[2])
- {
- QMessageBox::information(this,"","已经是所有库存了");
- return;
- }
- else
- {
- sum[2]+=1;
- ku[2]-=1;
- erdu+=much[2];
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab3_5->setText(QString::number(sum[2]));
- ui->lab3_4->setText(QString::number(ku[2]));
- }
- }
- //4
- void diang::on_pushButton_12_clicked()
- {
- if(sum[3]==0)
- {
- QMessageBox::information(this,"","已经是最少的了");
- return;
- }
- else
- {
- sum[3]-=1;
- ku[3]+=1;
- erdu-=much[3];
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab4_5->setText(QString::number(sum[3]));
- ui->lab4_4->setText(QString::number(ku[3]));
- }
- }
-
- void diang::on_pushButton_22_clicked()
- {
- if(sum[3]==yuan[3])
- {
-
- QMessageBox::information(this,"","已经是所有库存了");
- return;
- }
- else
- {
- sum[3]+=1;
- ku[3]-=1;
- erdu+=much[3];
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab4_5->setText(QString::number(sum[3]));
- ui->lab4_4->setText(QString::number(ku[3]));
- }
- }
- //5
- void diang::on_pushButton_13_clicked()
- {
- if(sum[4]==0)
- {
- QMessageBox::information(this,"","已经是最少的了");
- return;
- }
- else
- {
- sum[4]-=1;
- ku[4]+=1;
- erdu-=much[4];
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab5_5->setText(QString::number(sum[4]));
- ui->lab5_4->setText(QString::number(ku[4]));
- }
- }
-
- void diang::on_pushButton_23_clicked()
- {
- if(sum[4]==yuan[4])
- {
-
- QMessageBox::information(this,"","已经是所有库存了");
- return;
- }
- else
- {
- sum[4]+=1;
- ku[4]-=1;
- erdu+=much[4];
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab5_5->setText(QString::number(sum[4]));
- ui->lab5_4->setText(QString::number(ku[4]));
- }
- }
- //6
-
- void diang::on_pushButton_14_clicked()
- {
- if(sum[5]==0)
- {
- QMessageBox::information(this,"","已经是最少的了");
- return;
- }
- else
- {
- sum[5]-=1;
- ku[5]+=1;
- erdu-=much[5];
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab6_5->setText(QString::number(sum[5]));
- ui->lab6_4->setText(QString::number(ku[5]));
- }
- }
-
- void diang::on_pushButton_24_clicked()
- {
- if(sum[5]==yuan[5])
- {
-
- QMessageBox::information(this,"","已经是所有库存了");
- return;
- }
- else
- {
- sum[5]+=1;
- ku[5]-=1;
- erdu+=much[5];
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab6_5->setText(QString::number(sum[5]));
- ui->lab6_4->setText(QString::number(ku[5]));
- }
- }
- //7
-
-
- void diang::on_pushButton_15_clicked()
- {
- if(sum[6]==0)
- {
- QMessageBox::information(this,"","已经是最少的了");
- return;
- }
- else
- {
- sum[6]-=1;
- ku[6]+=1;
- erdu-=much[6];
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab7_5->setText(QString::number(sum[6]));
- ui->lab7_4->setText(QString::number(ku[6]));
- }
- }
-
- void diang::on_pushButton_25_clicked()
- {
- if(sum[6]==yuan[6])
- {
-
- QMessageBox::information(this,"","已经是所有库存了");
- return;
- }
- else
- {
- sum[6]+=1;
- ku[6]-=1;
- erdu+=much[6];
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab7_5->setText(QString::number(sum[6]));
- ui->lab7_4->setText(QString::number(ku[6]));
- }
- }
- //8
- void diang::on_pushButton_16_clicked()
- {
- if(sum[7]==0)
- {
- QMessageBox::information(this,"","已经是最少的了");
- return;
- }
- else
- {
- sum[7]-=1;
- ku[7]+=1;
- erdu-=much[7];
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab8_5->setText(QString::number(sum[7]));
- ui->lab8_4->setText(QString::number(ku[7]));
- }
- }
-
- void diang::on_pushButton_26_clicked()
- {
- if(sum[7]==yuan[7])
- {
-
- QMessageBox::information(this,"","已经是所有库存了");
- return;
- }
- else
- {
- sum[7]+=1;
- ku[7]-=1;
- erdu+=much[7];
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab8_5->setText(QString::number(sum[7]));
- ui->lab8_4->setText(QString::number(ku[7]));
- }
- }
- //9
-
- void diang::on_pushButton_17_clicked()
- {
- if(sum[8]==0)
- {
- QMessageBox::information(this,"","已经是最少的了");
- return;
- }
- else
- {
- sum[8]-=1;
- ku[8]+=1;
- erdu-=much[8];
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab9_5->setText(QString::number(sum[8]));
- ui->lab9_4->setText(QString::number(ku[8]));
- }
- }
-
- void diang::on_pushButton_27_clicked()
- {
- if(sum[8]==yuan[8])
- {
-
- QMessageBox::information(this,"","已经是所有库存了");
- return;
- }
- else
- {
- sum[8]+=1;
- ku[8]-=1;
- erdu+=much[8];
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab9_5->setText(QString::number(sum[8]));
- ui->lab9_4->setText(QString::number(ku[8]));
- }
- }
- //10
- void diang::on_pushButton_18_clicked()
- {
- if(sum[9]==0)
- {
- QMessageBox::information(this,"","已经是最少的了");
- return;
- }
- else
- {
- sum[9]-=1;
- ku[9]+=1;
- erdu-=much[9];
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab10_5->setText(QString::number(sum[9]));
- ui->lab10_4->setText(QString::number(ku[9]));
- }
- }
-
- void diang::on_pushButton_28_clicked()
- {
- if(sum[9]==yuan[9])
- {
-
- QMessageBox::information(this,"","已经是所有库存了");
- return;
- }
- else
- {
- sum[9]+=1;
- ku[9]-=1;
- erdu+=much[9];
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab10_5->setText(QString::number(sum[9]));
- ui->lab10_4->setText(QString::number(ku[9]));
- }
- }
- //11
-
-
- void diang::on_pushButton_19_clicked()
- {
- if(sum[10]==0)
- {
- QMessageBox::information(this,"","已经是最少的了");
- return;
- }
- else
- {
- sum[10]-=1;
- ku[10]+=1;
- erdu-=much[10];
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab11_5->setText(QString::number(sum[10]));
- ui->lab11_4->setText(QString::number(ku[10]));
- }
- }
-
- void diang::on_pushButton_29_clicked()
- {
- if(sum[10]==yuan[10])
- {
-
- QMessageBox::information(this,"","已经是所有库存了");
- return;
- }
- else
- {
- sum[10]+=1;
- ku[10]-=1;
- erdu+=much[10];
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab11_5->setText(QString::number(sum[10]));
- ui->lab11_4->setText(QString::number(ku[10]));
- }
- }
- //12
- void diang::on_pushButton_20_clicked()
- {
- if(sum[11]==0)
- {
- QMessageBox::information(this,"","已经是最少的了");
- return;
- }
- else
- {
- sum[11]-=1;
- ku[11]+=1;
- erdu-=much[11];
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab12_5->setText(QString::number(sum[11]));
- ui->lab12_4->setText(QString::number(ku[11]));
- }
- }
-
- void diang::on_pushButton_30_clicked()
- {
- if(sum[11]==yuan[11])
- {
-
- QMessageBox::information(this,"","已经是所有库存了");
- return;
- }
- else
- {
- sum[11]+=1;
- ku[11]-=1;
- erdu+=much[11];
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab12_5->setText(QString::number(sum[11]));
- ui->lab12_4->setText(QString::number(ku[11]));
- }
- }
- //购物车
- void diang::on_pushButton_clicked()
- {
- for(int i=0;i<12;i++)
- {
- if(sum[i]!=0)
- {
- QString date=ming[i];
- int date2=sum[i];
- emit xinjian(date,date2,i);
-
- }
- }
- this->hide();
- cai->show();
-
- }
- void diang::jajian(int datas)
- {
- if(sum[datas]==0)
- {
- QMessageBox::information(this,"","已经是最少的了");
-
- }
-
- qDebug()<<"datas"<<datas;
- sum[datas]-=1;
- ku[datas]+=1;
- erdu-=much[datas];
- switch(datas)
- {
- case 0:
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab1_5->setText(QString::number(sum[datas]));
- ui->lab1_4->setText(QString::number(ku[datas]));
- break;
- case 1:
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab2_5->setText(QString::number(sum[datas]));
- ui->lab2_4->setText(QString::number(ku[datas]));
- break;
- case 2:
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab3_5->setText(QString::number(sum[datas]));
- ui->lab3_4->setText(QString::number(ku[datas]));
- break;
- case 3:
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab4_5->setText(QString::number(sum[datas]));
- ui->lab4_4->setText(QString::number(ku[datas]));
- break;
- case 4:
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab5_5->setText(QString::number(sum[datas]));
- ui->lab5_4->setText(QString::number(ku[datas]));
- break;
- case 5:
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab6_5->setText(QString::number(sum[datas]));
- ui->lab6_4->setText(QString::number(ku[datas]));
- break;
- case 6:
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab7_5->setText(QString::number(sum[datas]));
- ui->lab7_4->setText(QString::number(ku[datas]));
- break;
- case 7:
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab8_5->setText(QString::number(sum[datas]));
- ui->lab8_4->setText(QString::number(ku[datas]));
- break;
- case 8:
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab9_5->setText(QString::number(sum[datas]));
- ui->lab9_4->setText(QString::number(ku[datas]));
- break;
- case 9:
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab10_5->setText(QString::number(sum[datas]));
- ui->lab10_4->setText(QString::number(ku[datas]));
- break;
- case 10:
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab11_5->setText(QString::number(sum[datas]));
- ui->lab11_4->setText(QString::number(ku[datas]));
- break;
- case 11:
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab12_5->setText(QString::number(sum[datas]));
- ui->lab12_4->setText(QString::number(ku[datas]));
- break;
-
- }
-
-
- }
- //加
- void diang::jiajian(int dates)
- {
- if(sum[dates]==yuan[dates])
- {
-
- QMessageBox::information(this,"","已经是所有库存了");
-
- }
-
- sum[dates]+=1;
- ku[dates]-=1;
- erdu+=much[dates];
- switch(dates)
- {
- case 0:
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab1_5->setText(QString::number(sum[dates]));
- ui->lab1_4->setText(QString::number(ku[dates]));
- break;
- case 1:
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab2_5->setText(QString::number(sum[dates]));
- ui->lab2_4->setText(QString::number(ku[dates]));
- break;
- case 2:
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab3_5->setText(QString::number(sum[dates]));
- ui->lab3_4->setText(QString::number(ku[dates]));
- break;
- case 3:
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab4_5->setText(QString::number(sum[dates]));
- ui->lab4_4->setText(QString::number(ku[dates]));
- break;
- case 4:
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab5_5->setText(QString::number(sum[dates]));
- ui->lab5_4->setText(QString::number(ku[dates]));
- break;
- case 5:
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab6_5->setText(QString::number(sum[dates]));
- ui->lab6_4->setText(QString::number(ku[dates]));
- break;
- case 6:
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab7_5->setText(QString::number(sum[dates]));
- ui->lab7_4->setText(QString::number(ku[dates]));
- break;
- case 7:
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab8_5->setText(QString::number(sum[dates]));
- ui->lab8_4->setText(QString::number(ku[dates]));
- break;
- case 8:
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab9_5->setText(QString::number(sum[dates]));
- ui->lab9_4->setText(QString::number(ku[dates]));
- break;
- case 9:
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab10_5->setText(QString::number(sum[dates]));
- ui->lab10_4->setText(QString::number(ku[dates]));
- break;
- case 10:
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab11_5->setText(QString::number(sum[dates]));
- ui->lab11_4->setText(QString::number(ku[dates]));
- break;
- case 11:
- ui->lineEdit->setText(QString::number(erdu));
- ui->lab12_5->setText(QString::number(sum[dates]));
- ui->lab12_4->setText(QString::number(ku[dates]));
- break;
- }
-
- }
- //购物车界面
- #include "cede.h"
- #include "ui_cede.h"
- #include "diang.h"
- diang* qing;
- //按钮名
- QString put[12]={"put1","put2","put3","put4","put5","put6","put7","put8","put9","put10","put11","put12"};
- //label名
- QString lae[12]={"labt1","labt2","labt3","labt4","labt5","labt6","labt7","labt8","labt9","labt10","labt11","labt12"};
- //edix名
- QString txt[12]={"edi1","edi2","edi3","edi4","edi5","edi6","edi7","edi8","edi9","edi10","edi11","edi12"};
- //(加)按钮
- QString an[12]={"an1","an2","an3","an4","an5","an6","an7","an8","an9","an10","an11","an12"};
-
- // 声明一个容器来存储已创建的控件指针
- QList<QWidget*> createdWidgets;
-
- cede::cede(QWidget *parent) :
- QWidget(parent),
- ui(new Ui::cede)
- {
- ui->setupUi(this);
- //显示一个单独的窗口
- setWindowFlags(Qt::Window);
- //找寻父界面
- QWidget* s=parentWidget();
- //转化类型
- qing = dynamic_cast<diang*>(s);
- //连接信号和槽函数
- connect(this,&cede::toj,qing,&diang::jajian);
- //加法
- connect(this,&cede::tos,qing,&diang::jiajian);
- }
-
- cede::~cede()
- {
- delete ui;
- }
- //槽
- void cede::chuan(QString date, int date2,int infos)
- {
- QHBoxLayout* horizontalLayout = new QHBoxLayout(this);
- qDebug()<<infos;
- //创建Qlabel控件
- QLabel* labet=new QLabel(date,this);
- labet->setObjectName(lae[infos]);
- //qDebug()<<labet->objectName();
- labet->setFixedSize(100,100);
- createdWidgets.append(labet);
- //创建QTextEdit
- QTextEdit* textEdit = new QTextEdit(QString::number(date2),this);
- textEdit->setObjectName(txt[infos]);
- textEdit->setFixedSize(50,50);
- createdWidgets.append(textEdit);
- //创建按钮
- QPushButton* jia=new QPushButton("-",this);
- jia->setObjectName(put[infos]);
- connect(jia,&QPushButton::clicked,this,&cede::jianButtonclick);
- jia->setFixedSize(80,50);
- createdWidgets.append(jia);
- QPushButton* jian=new QPushButton("+",this);
- jian->setObjectName(an[infos]);
- connect(jian,&QPushButton::clicked,this,&cede::jiaButtonclick);
- jian->setFixedSize(50,50);
- createdWidgets.append(jian);
- //添加到水平布局
- horizontalLayout->addWidget(labet);
- horizontalLayout->addSpacing(10);
- horizontalLayout->addWidget(jia);
- horizontalLayout->addSpacing(10);
- horizontalLayout->addWidget(textEdit);
- horizontalLayout->addSpacing(10);
- horizontalLayout->addWidget(jian);
-
- // 获取当前Widget的布局
- QVBoxLayout* mainLayout = qobject_cast<QVBoxLayout*>(layout());
-
- // 将水平布局添加到垂直布局
- mainLayout->addLayout(horizontalLayout);
-
-
- }
- //减
- void cede::jianButtonclick()
- {
- //获取按钮属性
- QPushButton* senderButton = qobject_cast<QPushButton*>(sender());
- if(senderButton&&senderButton->objectName()==put[0])
- {
- QTextEdit* textEdit=findChild<QTextEdit*>("edi1");
- if(textEdit)
- {
- QString stc=textEdit->toPlainText();
- //转化
- int k=stc.toInt();
- if(k==0)
- {
-
- QMessageBox::information(this,"","已经是最少的了");
- qDebug()<<k;
- return;
- }
- k-=1;
- textEdit->setText(QString::number(k));
- }
- emit toj(0);
- }
- else if(senderButton&&senderButton->objectName()==put[1])
- {
- QTextEdit* textEdit=findChild<QTextEdit*>("edi2");
- if(textEdit)
- {
- QString stc=textEdit->toPlainText();
- //转化
- int k=stc.toInt();
- if(k==0)
- {
-
- QMessageBox::information(this,"","已经是最少的了");
- return;
- }
- k-=1;
- textEdit->setText(QString::number(k));
- }
- emit toj(1);
- }
- else if(senderButton&&senderButton->objectName()==put[2])
- {
- QTextEdit* textEdit=findChild<QTextEdit*>("edi3");
- if(textEdit)
- {
- QString stc=textEdit->toPlainText();
- //转化
- int k=stc.toInt();
- if(k==0)
- {
-
- QMessageBox::information(this,"","已经是最少的了");
- return;
- }
- k-=1;
- textEdit->setText(QString::number(k));
- }
- emit toj(2);
- }
- else if(senderButton&&senderButton->objectName()==put[3])
- {
- QTextEdit* textEdit=findChild<QTextEdit*>("edi4");
- if(textEdit)
- {
- QString stc=textEdit->toPlainText();
- //转化
- int k=stc.toInt();
- if(k==0)
- {
-
- QMessageBox::information(this,"","已经是最少的了");
- return;
- }
- k-=1;
- textEdit->setText(QString::number(k));
- }
- emit toj(3);
- }
- else if(senderButton&&senderButton->objectName()==put[4])
- {
- QTextEdit* textEdit=findChild<QTextEdit*>(txt[4]);
- if(textEdit)
- {
- QString stc=textEdit->toPlainText();
- //转化
- int k=stc.toInt();
- if(k==0)
- {
-
- QMessageBox::information(this,"","已经是最少的了");
- return;
- }
- k-=1;
- textEdit->setText(QString::number(k));
- }
- emit toj(3);
- }
- else if(senderButton&&senderButton->objectName()==put[5])
- {
- QTextEdit* textEdit=findChild<QTextEdit*>(txt[5]);
- if(textEdit)
- {
- QString stc=textEdit->toPlainText();
- //转化
- int k=stc.toInt();
- if(k==0)
- {
-
- QMessageBox::information(this,"","已经是最少的了");
- return;
- }
- k-=1;
- textEdit->setText(QString::number(k));
- }
- emit toj(3);
- }
- else if(senderButton&&senderButton->objectName()==put[6])
- {
- QTextEdit* textEdit=findChild<QTextEdit*>(txt[6]);
- if(textEdit)
- {
- QString stc=textEdit->toPlainText();
- //转化
- int k=stc.toInt();
- if(k==0)
- {
-
- QMessageBox::information(this,"","已经是最少的了");
- return;
- }
- k-=1;
- textEdit->setText(QString::number(k));
- }
- emit toj(3);
- }
- else if(senderButton&&senderButton->objectName()==put[7])
- {
- QTextEdit* textEdit=findChild<QTextEdit*>(txt[7]);
- if(textEdit)
- {
- QString stc=textEdit->toPlainText();
- //转化
- int k=stc.toInt();
- if(k==0)
- {
-
- QMessageBox::information(this,"","已经是最少的了");
- return;
- }
- k-=1;
- textEdit->setText(QString::number(k));
- }
- emit toj(3);
- }
- else if(senderButton&&senderButton->objectName()==put[8])
- {
- QTextEdit* textEdit=findChild<QTextEdit*>(txt[8]);
- if(textEdit)
- {
- QString stc=textEdit->toPlainText();
- //转化
- int k=stc.toInt();
- if(k==0)
- {
-
- QMessageBox::information(this,"","已经是最少的了");
- return;
- }
- k-=1;
- textEdit->setText(QString::number(k));
- }
- emit toj(3);
- }
- else if(senderButton&&senderButton->objectName()==put[9])
- {
- QTextEdit* textEdit=findChild<QTextEdit*>(txt[9]);
- if(textEdit)
- {
- QString stc=textEdit->toPlainText();
- //转化
- int k=stc.toInt();
- if(k==0)
- {
-
- QMessageBox::information(this,"","已经是最少的了");
- return;
- }
- k-=1;
- textEdit->setText(QString::number(k));
- }
- emit toj(3);
- }
- else if(senderButton&&senderButton->objectName()==put[10])
- {
- QTextEdit* textEdit=findChild<QTextEdit*>(txt[10]);
- if(textEdit)
- {
- QString stc=textEdit->toPlainText();
- //转化
- int k=stc.toInt();
- if(k==0)
- {
-
- QMessageBox::information(this,"","已经是最少的了");
- return;
- }
- k-=1;
- textEdit->setText(QString::number(k));
- }
- emit toj(3);
- }
- else if(senderButton&&senderButton->objectName()==put[11])
- {
- QTextEdit* textEdit=findChild<QTextEdit*>(txt[11]);
- if(textEdit)
- {
- QString stc=textEdit->toPlainText();
- //转化
- int k=stc.toInt();
- if(k==0)
- {
-
- QMessageBox::information(this,"","已经是最少的了");
- return;
- }
- k-=1;
- textEdit->setText(QString::number(k));
- }
- emit toj(3);
- }
-
- }
-
- //加
- void cede::jiaButtonclick()
- {
- QPushButton* senderButton = qobject_cast<QPushButton*>(sender());
- if(senderButton&&senderButton->objectName()==an[0])
- {
- QTextEdit* textEdit=findChild<QTextEdit*>("edi1");
- if(textEdit)
- {
- QString stc=textEdit->toPlainText();
- //转化
- int k=stc.toInt();
- if(k==10)
- {
-
- QMessageBox::information(this,"","已经是最多的了");
- return;
- }
- k+=1;
- textEdit->setText(QString::number(k));
- }
- emit tos(0);
- }
- else if(senderButton&&senderButton->objectName()==an[1])
- {
- QTextEdit* textEdit=findChild<QTextEdit*>("edi2");
- if(textEdit)
- {
- QString stc=textEdit->toPlainText();
- //转化
- int k=stc.toInt();
- if(k==10)
- {
-
- QMessageBox::information(this,"","已经是最多的了");
- return;
- }
- k+=1;
- textEdit->setText(QString::number(k));
- }
- emit tos(1);
- }
- else if(senderButton&&senderButton->objectName()==an[2])
- {
- QTextEdit* textEdit=findChild<QTextEdit*>("edi3");
- if(textEdit)
- {
- QString stc=textEdit->toPlainText();
- //转化
- int k=stc.toInt();
- if(k==10)
- {
-
- QMessageBox::information(this,"","已经是最多的了");
- return;
- }
- k+=1;
- textEdit->setText(QString::number(k));
- }
-
- emit tos(2);
- }
- else if(senderButton&&senderButton->objectName()==an[3])
- {
- QTextEdit* textEdit=findChild<QTextEdit*>("edi4");
- if(textEdit)
- {
- QString stc=textEdit->toPlainText();
- //转化
- int k=stc.toInt();
- if(k==10)
- {
-
- QMessageBox::information(this,"","已经是最多的了");
- return;
- }
- k+=1;
- textEdit->setText(QString::number(k));
- }
-
- emit tos(3);
- }
- else if(senderButton&&senderButton->objectName()==an[4])
- {
- QTextEdit* textEdit=findChild<QTextEdit*>(txt[4]);
- if(textEdit)
- {
- QString stc=textEdit->toPlainText();
- //转化
- int k=stc.toInt();
- if(k==10)
- {
-
- QMessageBox::information(this,"","已经是最多的了");
- return;
- }
- k+=1;
- textEdit->setText(QString::number(k));
- }
-
- emit tos(3);
- }
- else if(senderButton&&senderButton->objectName()==an[5])
- {
- QTextEdit* textEdit=findChild<QTextEdit*>(txt[5]);
- if(textEdit)
- {
- QString stc=textEdit->toPlainText();
- //转化
- int k=stc.toInt();
- if(k==10)
- {
-
- QMessageBox::information(this,"","已经是最多的了");
- return;
- }
- k+=1;
- textEdit->setText(QString::number(k));
- }
-
- emit tos(3);
- }
- else if(senderButton&&senderButton->objectName()==an[6])
- {
- QTextEdit* textEdit=findChild<QTextEdit*>(txt[6]);
- if(textEdit)
- {
- QString stc=textEdit->toPlainText();
- //转化
- int k=stc.toInt();
- if(k==10)
- {
-
- QMessageBox::information(this,"","已经是最多的了");
- return;
- }
- k+=1;
- textEdit->setText(QString::number(k));
- }
-
- emit tos(3);
- }
- else if(senderButton&&senderButton->objectName()==an[7])
- {
- QTextEdit* textEdit=findChild<QTextEdit*>(txt[7]);
- if(textEdit)
- {
- QString stc=textEdit->toPlainText();
- //转化
- int k=stc.toInt();
- if(k==10)
- {
-
- QMessageBox::information(this,"","已经是最多的了");
- return;
- }
- k+=1;
- textEdit->setText(QString::number(k));
- }
-
- emit tos(3);
- }
- else if(senderButton&&senderButton->objectName()==an[8])
- {
- QTextEdit* textEdit=findChild<QTextEdit*>(txt[8]);
- if(textEdit)
- {
- QString stc=textEdit->toPlainText();
- //转化
- int k=stc.toInt();
- if(k==10)
- {
-
- QMessageBox::information(this,"","已经是最多的了");
- return;
- }
- k+=1;
- textEdit->setText(QString::number(k));
- }
-
- emit tos(3);
- }
- else if(senderButton&&senderButton->objectName()==an[9])
- {
- QTextEdit* textEdit=findChild<QTextEdit*>(txt[9]);
- if(textEdit)
- {
- QString stc=textEdit->toPlainText();
- //转化
- int k=stc.toInt();
- if(k==10)
- {
-
- QMessageBox::information(this,"","已经是最多的了");
- return;
- }
- k+=1;
- textEdit->setText(QString::number(k));
- }
-
- emit tos(3);
- }
- else if(senderButton&&senderButton->objectName()==an[10])
- {
- QTextEdit* textEdit=findChild<QTextEdit*>(txt[10]);
- if(textEdit)
- {
- QString stc=textEdit->toPlainText();
- //转化
- int k=stc.toInt();
- if(k==10)
- {
-
- QMessageBox::information(this,"","已经是最多的了");
- return;
- }
- k+=1;
- textEdit->setText(QString::number(k));
- }
-
- emit tos(3);
- }
- else if(senderButton&&senderButton->objectName()==an[11])
- {
- QTextEdit* textEdit=findChild<QTextEdit*>(txt[11]);
- if(textEdit)
- {
- QString stc=textEdit->toPlainText();
- //转化
- int k=stc.toInt();
- if(k==10)
- {
-
- QMessageBox::information(this,"","已经是最多的了");
- return;
- }
- k+=1;
- textEdit->setText(QString::number(k));
- }
-
- emit tos(3);
- }
- }
- //退回
- void cede::on_pushButton_clicked()
- {
- this->hide();
- for (QWidget* widget : createdWidgets)
- {
- // 从布局中移除控件(如果有的话)
- if (QLayout* layout = qobject_cast<QLayout*>(widget->parent())) {
- layout->removeWidget(widget);
- }
- // 删除控件
- delete widget;
- }
- //清空容器
- createdWidgets.clear();
- qing->show();
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。