当前位置:   article > 正文

使用QT实现点餐ui界面_qt点餐系统

qt点餐系统

通过在QT中对界面进行设计,使界面实现

1、登录/注册功能

2、点餐功能(显示图片、库存、点菜数量)

3、购物车界面(对已点的菜品进行总结,点了哪些菜品就显示哪些菜品的点菜数量)

  1. //主界面(登录界面)
  2. #include "mainwindow.h"
  3. #include "ui_mainwindow.h"
  4. #include "zuce.h"
  5. #include "diang.h"
  6. diang* food;
  7. MainWindow::MainWindow(QWidget *parent)
  8. : QMainWindow(parent)
  9. , ui(new Ui::MainWindow)
  10. {
  11. ui->setupUi(this);
  12. }
  13. MainWindow::~MainWindow()
  14. {
  15. delete ui;
  16. }
  17. //自定义槽
  18. void MainWindow::jian(QString data)
  19. {
  20. //存储账号和密码
  21. list<<data;
  22. }
  23. //登录
  24. void MainWindow::on_pushButton_clicked()
  25. {
  26. int info=0;
  27. static int num=3;
  28. QString data=ui->ledit1->text()+"#"+ui->ledit2->text();
  29. for(int i=0;i<list.size();i++)
  30. {
  31. if(data==list[i])
  32. {
  33. qDebug()<<"登录成功";
  34. QMessageBox::information(this,"", "登录成功");
  35. info=1;
  36. break;
  37. }
  38. }
  39. if(info==0)
  40. {
  41. //清空输入框
  42. ui->ledit1->clear();
  43. ui->ledit2->clear();
  44. qDebug()<<"登录失败";
  45. num--;
  46. QString tex="账号密码错误,你还剩"+QString::number(num)+"次机会";
  47. //qDebug()<<"你还剩"<<num<<"次机会";
  48. QMessageBox::information(this,"",tex);
  49. }
  50. //登录成功后的界面
  51. if(info==1)
  52. {
  53. //生成点餐界面
  54. food=new diang(nullptr);
  55. this->hide();
  56. food->show();
  57. }
  58. //次数用完就关闭
  59. if(num==0)
  60. this->close();
  61. }
  62. //注册
  63. void MainWindow::on_pushButton_2_clicked()
  64. {
  65. zuce* ZC=new zuce(this);
  66. this->hide();
  67. ZC->show();
  68. }
  1. //注册界面
  2. #include "zuce.h"
  3. #include "ui_zuce.h"
  4. #include "mainwindow.h"
  5. #include<QDebug>
  6. MainWindow* fu;
  7. zuce::zuce(QWidget *parent) :
  8. QMainWindow(parent),
  9. ui(new Ui::zuce)
  10. {
  11. ui->setupUi(this);
  12. //找到父界面
  13. QWidget* w=parentWidget();
  14. //转化类型
  15. fu = dynamic_cast<MainWindow*>(w);
  16. //连接信号和槽函数
  17. connect(this,&zuce::che,fu,&MainWindow::jian);
  18. }
  19. zuce::~zuce()
  20. {
  21. delete ui;
  22. }
  23. void zuce::on_pushButton_2_clicked()
  24. {
  25. this->hide();
  26. fu->show();
  27. }
  28. void zuce::on_pushButton_clicked()
  29. {
  30. QString word=ui->zuce1->text();//账号
  31. QString pass=ui->zuce2->text();//密码
  32. ui->zuce1->clear();
  33. ui->zuce2->clear();
  34. QString data=word+'#'+pass;
  35. lis<<data;
  36. for(int i=0;i<lis.size();i++)
  37. {
  38. qDebug()<<lis[i];
  39. }
  40. //发送信号
  41. emit che(data);
  42. }
  1. //点餐界面
  2. #include "diang.h"
  3. #include "ui_diang.h"
  4. #include "mainwindow.h"
  5. #include "cede.h"
  6. cede* cai;
  7. //菜名
  8. QString ming[12]={"麻辣窝窝头","黄金凤尾虾","糖果炒肉","福袋","好看的福袋","枫达","一人嘉禾","鸡你太莓","仰望星空","炸坤排","ikun工作餐","狱卒"};
  9. //数量
  10. int sum[12]={};
  11. //价格
  12. int much[12]={15,30,25,30,50,10,2,15,198,20,35,998};
  13. //原库存
  14. int yuan[12]={10,10,10,10,10,10,100,10,10,10,10,10};
  15. //库存
  16. int ku[12]={10,10,10,10,10,10,100,10,10,10,10,10};
  17. //总金额
  18. int erdu=0;
  19. diang::diang(QWidget *parent) :
  20. QWidget(parent),
  21. ui(new Ui::diang)
  22. {
  23. ui->setupUi(this);
  24. //库存
  25. ui->lab1_4->setText(QString::number(ku[0]));
  26. ui->lab2_4->setText(QString::number(ku[1]));
  27. ui->lab3_4->setText(QString::number(ku[2]));
  28. ui->lab4_4->setText(QString::number(ku[3]));
  29. ui->lab5_4->setText(QString::number(ku[4]));
  30. ui->lab6_4->setText(QString::number(ku[5]));
  31. ui->lab7_4->setText(QString::number(ku[6]));
  32. ui->lab8_4->setText(QString::number(ku[7]));
  33. ui->lab9_4->setText(QString::number(ku[8]));
  34. ui->lab10_4->setText(QString::number(ku[9]));
  35. ui->lab11_4->setText(QString::number(ku[10]));
  36. ui->lab12_4->setText(QString::number(ku[11]));
  37. //数量
  38. ui->lab1_5->setText(QString::number(sum[0]));
  39. ui->lab2_5->setText(QString::number(sum[1]));
  40. ui->lab3_5->setText(QString::number(sum[2]));
  41. ui->lab4_5->setText(QString::number(sum[3]));
  42. ui->lab5_5->setText(QString::number(sum[4]));
  43. ui->lab6_5->setText(QString::number(sum[5]));
  44. ui->lab7_5->setText(QString::number(sum[6]));
  45. ui->lab8_5->setText(QString::number(sum[7]));
  46. ui->lab9_5->setText(QString::number(sum[8]));
  47. ui->lab10_5->setText(QString::number(sum[9]));
  48. ui->lab11_5->setText(QString::number(sum[10]));
  49. ui->lab12_5->setText(QString::number(sum[11]));
  50. cai=new cede(this);
  51. cai->hide();
  52. //连接信号和槽
  53. connect(this,&diang::xinjian,cai,&cede::chuan);
  54. }
  55. diang::~diang()
  56. {
  57. delete ui;
  58. }
  59. void diang::on_pushButton_2_clicked()
  60. {
  61. QMessageBox::information(this,"","坤坤正在火热为你制作");
  62. }
  63. //1
  64. void diang::on_pushButton_3_clicked()
  65. {
  66. if(sum[0]==0)
  67. {
  68. QMessageBox::information(this,"","已经是最少的了");
  69. return;
  70. }
  71. else
  72. {
  73. sum[0]-=1;
  74. ku[0]+=1;
  75. erdu-=much[0];
  76. ui->lineEdit->setText(QString::number(erdu));
  77. ui->lab1_5->setText(QString::number(sum[0]));
  78. ui->lab1_4->setText(QString::number(ku[0]));
  79. }
  80. }
  81. void diang::on_pushButton_4_clicked()
  82. {
  83. if(sum[0]==yuan[0])
  84. {
  85. QMessageBox::information(this,"","已经是所有库存了");
  86. return;
  87. }
  88. else
  89. {
  90. sum[0]+=1;
  91. ku[0]-=1;
  92. erdu+=much[0];
  93. ui->lineEdit->setText(QString::number(erdu));
  94. ui->lab1_5->setText(QString::number(sum[0]));
  95. ui->lab1_4->setText(QString::number(ku[0]));
  96. }
  97. }
  98. //2
  99. void diang::on_pushButton_5_clicked()
  100. {
  101. if(sum[1]==0)
  102. {
  103. QMessageBox::information(this,"","已经是最少的了");
  104. return;
  105. }
  106. else
  107. {
  108. sum[1]-=1;
  109. ku[1]+=1;
  110. erdu-=much[1];
  111. ui->lineEdit->setText(QString::number(erdu));
  112. ui->lab2_5->setText(QString::number(sum[1]));
  113. ui->lab2_4->setText(QString::number(ku[1]));
  114. }
  115. }
  116. void diang::on_pushButton_6_clicked()
  117. {
  118. if(sum[1]==yuan[1])
  119. {
  120. QMessageBox::information(this,"","已经是所有库存了");
  121. return;
  122. }
  123. else
  124. {
  125. sum[1]+=1;
  126. ku[1]-=1;
  127. erdu+=much[1];
  128. ui->lineEdit->setText(QString::number(erdu));
  129. ui->lab2_5->setText(QString::number(sum[1]));
  130. ui->lab2_4->setText(QString::number(ku[1]));
  131. }
  132. }
  133. //3
  134. void diang::on_pushButton_11_clicked()
  135. {
  136. if(sum[2]==0)
  137. {
  138. QMessageBox::information(this,"","已经是最少的了");
  139. return;
  140. }
  141. else
  142. {
  143. sum[2]-=1;
  144. ku[2]+=1;
  145. erdu-=much[2];
  146. ui->lineEdit->setText(QString::number(erdu));
  147. ui->lab3_5->setText(QString::number(sum[2]));
  148. ui->lab3_4->setText(QString::number(ku[2]));
  149. }
  150. }
  151. void diang::on_pushButton_21_clicked()
  152. {
  153. if(sum[2]==yuan[2])
  154. {
  155. QMessageBox::information(this,"","已经是所有库存了");
  156. return;
  157. }
  158. else
  159. {
  160. sum[2]+=1;
  161. ku[2]-=1;
  162. erdu+=much[2];
  163. ui->lineEdit->setText(QString::number(erdu));
  164. ui->lab3_5->setText(QString::number(sum[2]));
  165. ui->lab3_4->setText(QString::number(ku[2]));
  166. }
  167. }
  168. //4
  169. void diang::on_pushButton_12_clicked()
  170. {
  171. if(sum[3]==0)
  172. {
  173. QMessageBox::information(this,"","已经是最少的了");
  174. return;
  175. }
  176. else
  177. {
  178. sum[3]-=1;
  179. ku[3]+=1;
  180. erdu-=much[3];
  181. ui->lineEdit->setText(QString::number(erdu));
  182. ui->lab4_5->setText(QString::number(sum[3]));
  183. ui->lab4_4->setText(QString::number(ku[3]));
  184. }
  185. }
  186. void diang::on_pushButton_22_clicked()
  187. {
  188. if(sum[3]==yuan[3])
  189. {
  190. QMessageBox::information(this,"","已经是所有库存了");
  191. return;
  192. }
  193. else
  194. {
  195. sum[3]+=1;
  196. ku[3]-=1;
  197. erdu+=much[3];
  198. ui->lineEdit->setText(QString::number(erdu));
  199. ui->lab4_5->setText(QString::number(sum[3]));
  200. ui->lab4_4->setText(QString::number(ku[3]));
  201. }
  202. }
  203. //5
  204. void diang::on_pushButton_13_clicked()
  205. {
  206. if(sum[4]==0)
  207. {
  208. QMessageBox::information(this,"","已经是最少的了");
  209. return;
  210. }
  211. else
  212. {
  213. sum[4]-=1;
  214. ku[4]+=1;
  215. erdu-=much[4];
  216. ui->lineEdit->setText(QString::number(erdu));
  217. ui->lab5_5->setText(QString::number(sum[4]));
  218. ui->lab5_4->setText(QString::number(ku[4]));
  219. }
  220. }
  221. void diang::on_pushButton_23_clicked()
  222. {
  223. if(sum[4]==yuan[4])
  224. {
  225. QMessageBox::information(this,"","已经是所有库存了");
  226. return;
  227. }
  228. else
  229. {
  230. sum[4]+=1;
  231. ku[4]-=1;
  232. erdu+=much[4];
  233. ui->lineEdit->setText(QString::number(erdu));
  234. ui->lab5_5->setText(QString::number(sum[4]));
  235. ui->lab5_4->setText(QString::number(ku[4]));
  236. }
  237. }
  238. //6
  239. void diang::on_pushButton_14_clicked()
  240. {
  241. if(sum[5]==0)
  242. {
  243. QMessageBox::information(this,"","已经是最少的了");
  244. return;
  245. }
  246. else
  247. {
  248. sum[5]-=1;
  249. ku[5]+=1;
  250. erdu-=much[5];
  251. ui->lineEdit->setText(QString::number(erdu));
  252. ui->lab6_5->setText(QString::number(sum[5]));
  253. ui->lab6_4->setText(QString::number(ku[5]));
  254. }
  255. }
  256. void diang::on_pushButton_24_clicked()
  257. {
  258. if(sum[5]==yuan[5])
  259. {
  260. QMessageBox::information(this,"","已经是所有库存了");
  261. return;
  262. }
  263. else
  264. {
  265. sum[5]+=1;
  266. ku[5]-=1;
  267. erdu+=much[5];
  268. ui->lineEdit->setText(QString::number(erdu));
  269. ui->lab6_5->setText(QString::number(sum[5]));
  270. ui->lab6_4->setText(QString::number(ku[5]));
  271. }
  272. }
  273. //7
  274. void diang::on_pushButton_15_clicked()
  275. {
  276. if(sum[6]==0)
  277. {
  278. QMessageBox::information(this,"","已经是最少的了");
  279. return;
  280. }
  281. else
  282. {
  283. sum[6]-=1;
  284. ku[6]+=1;
  285. erdu-=much[6];
  286. ui->lineEdit->setText(QString::number(erdu));
  287. ui->lab7_5->setText(QString::number(sum[6]));
  288. ui->lab7_4->setText(QString::number(ku[6]));
  289. }
  290. }
  291. void diang::on_pushButton_25_clicked()
  292. {
  293. if(sum[6]==yuan[6])
  294. {
  295. QMessageBox::information(this,"","已经是所有库存了");
  296. return;
  297. }
  298. else
  299. {
  300. sum[6]+=1;
  301. ku[6]-=1;
  302. erdu+=much[6];
  303. ui->lineEdit->setText(QString::number(erdu));
  304. ui->lab7_5->setText(QString::number(sum[6]));
  305. ui->lab7_4->setText(QString::number(ku[6]));
  306. }
  307. }
  308. //8
  309. void diang::on_pushButton_16_clicked()
  310. {
  311. if(sum[7]==0)
  312. {
  313. QMessageBox::information(this,"","已经是最少的了");
  314. return;
  315. }
  316. else
  317. {
  318. sum[7]-=1;
  319. ku[7]+=1;
  320. erdu-=much[7];
  321. ui->lineEdit->setText(QString::number(erdu));
  322. ui->lab8_5->setText(QString::number(sum[7]));
  323. ui->lab8_4->setText(QString::number(ku[7]));
  324. }
  325. }
  326. void diang::on_pushButton_26_clicked()
  327. {
  328. if(sum[7]==yuan[7])
  329. {
  330. QMessageBox::information(this,"","已经是所有库存了");
  331. return;
  332. }
  333. else
  334. {
  335. sum[7]+=1;
  336. ku[7]-=1;
  337. erdu+=much[7];
  338. ui->lineEdit->setText(QString::number(erdu));
  339. ui->lab8_5->setText(QString::number(sum[7]));
  340. ui->lab8_4->setText(QString::number(ku[7]));
  341. }
  342. }
  343. //9
  344. void diang::on_pushButton_17_clicked()
  345. {
  346. if(sum[8]==0)
  347. {
  348. QMessageBox::information(this,"","已经是最少的了");
  349. return;
  350. }
  351. else
  352. {
  353. sum[8]-=1;
  354. ku[8]+=1;
  355. erdu-=much[8];
  356. ui->lineEdit->setText(QString::number(erdu));
  357. ui->lab9_5->setText(QString::number(sum[8]));
  358. ui->lab9_4->setText(QString::number(ku[8]));
  359. }
  360. }
  361. void diang::on_pushButton_27_clicked()
  362. {
  363. if(sum[8]==yuan[8])
  364. {
  365. QMessageBox::information(this,"","已经是所有库存了");
  366. return;
  367. }
  368. else
  369. {
  370. sum[8]+=1;
  371. ku[8]-=1;
  372. erdu+=much[8];
  373. ui->lineEdit->setText(QString::number(erdu));
  374. ui->lab9_5->setText(QString::number(sum[8]));
  375. ui->lab9_4->setText(QString::number(ku[8]));
  376. }
  377. }
  378. //10
  379. void diang::on_pushButton_18_clicked()
  380. {
  381. if(sum[9]==0)
  382. {
  383. QMessageBox::information(this,"","已经是最少的了");
  384. return;
  385. }
  386. else
  387. {
  388. sum[9]-=1;
  389. ku[9]+=1;
  390. erdu-=much[9];
  391. ui->lineEdit->setText(QString::number(erdu));
  392. ui->lab10_5->setText(QString::number(sum[9]));
  393. ui->lab10_4->setText(QString::number(ku[9]));
  394. }
  395. }
  396. void diang::on_pushButton_28_clicked()
  397. {
  398. if(sum[9]==yuan[9])
  399. {
  400. QMessageBox::information(this,"","已经是所有库存了");
  401. return;
  402. }
  403. else
  404. {
  405. sum[9]+=1;
  406. ku[9]-=1;
  407. erdu+=much[9];
  408. ui->lineEdit->setText(QString::number(erdu));
  409. ui->lab10_5->setText(QString::number(sum[9]));
  410. ui->lab10_4->setText(QString::number(ku[9]));
  411. }
  412. }
  413. //11
  414. void diang::on_pushButton_19_clicked()
  415. {
  416. if(sum[10]==0)
  417. {
  418. QMessageBox::information(this,"","已经是最少的了");
  419. return;
  420. }
  421. else
  422. {
  423. sum[10]-=1;
  424. ku[10]+=1;
  425. erdu-=much[10];
  426. ui->lineEdit->setText(QString::number(erdu));
  427. ui->lab11_5->setText(QString::number(sum[10]));
  428. ui->lab11_4->setText(QString::number(ku[10]));
  429. }
  430. }
  431. void diang::on_pushButton_29_clicked()
  432. {
  433. if(sum[10]==yuan[10])
  434. {
  435. QMessageBox::information(this,"","已经是所有库存了");
  436. return;
  437. }
  438. else
  439. {
  440. sum[10]+=1;
  441. ku[10]-=1;
  442. erdu+=much[10];
  443. ui->lineEdit->setText(QString::number(erdu));
  444. ui->lab11_5->setText(QString::number(sum[10]));
  445. ui->lab11_4->setText(QString::number(ku[10]));
  446. }
  447. }
  448. //12
  449. void diang::on_pushButton_20_clicked()
  450. {
  451. if(sum[11]==0)
  452. {
  453. QMessageBox::information(this,"","已经是最少的了");
  454. return;
  455. }
  456. else
  457. {
  458. sum[11]-=1;
  459. ku[11]+=1;
  460. erdu-=much[11];
  461. ui->lineEdit->setText(QString::number(erdu));
  462. ui->lab12_5->setText(QString::number(sum[11]));
  463. ui->lab12_4->setText(QString::number(ku[11]));
  464. }
  465. }
  466. void diang::on_pushButton_30_clicked()
  467. {
  468. if(sum[11]==yuan[11])
  469. {
  470. QMessageBox::information(this,"","已经是所有库存了");
  471. return;
  472. }
  473. else
  474. {
  475. sum[11]+=1;
  476. ku[11]-=1;
  477. erdu+=much[11];
  478. ui->lineEdit->setText(QString::number(erdu));
  479. ui->lab12_5->setText(QString::number(sum[11]));
  480. ui->lab12_4->setText(QString::number(ku[11]));
  481. }
  482. }
  483. //购物车
  484. void diang::on_pushButton_clicked()
  485. {
  486. for(int i=0;i<12;i++)
  487. {
  488. if(sum[i]!=0)
  489. {
  490. QString date=ming[i];
  491. int date2=sum[i];
  492. emit xinjian(date,date2,i);
  493. }
  494. }
  495. this->hide();
  496. cai->show();
  497. }
  498. void diang::jajian(int datas)
  499. {
  500. if(sum[datas]==0)
  501. {
  502. QMessageBox::information(this,"","已经是最少的了");
  503. }
  504. qDebug()<<"datas"<<datas;
  505. sum[datas]-=1;
  506. ku[datas]+=1;
  507. erdu-=much[datas];
  508. switch(datas)
  509. {
  510. case 0:
  511. ui->lineEdit->setText(QString::number(erdu));
  512. ui->lab1_5->setText(QString::number(sum[datas]));
  513. ui->lab1_4->setText(QString::number(ku[datas]));
  514. break;
  515. case 1:
  516. ui->lineEdit->setText(QString::number(erdu));
  517. ui->lab2_5->setText(QString::number(sum[datas]));
  518. ui->lab2_4->setText(QString::number(ku[datas]));
  519. break;
  520. case 2:
  521. ui->lineEdit->setText(QString::number(erdu));
  522. ui->lab3_5->setText(QString::number(sum[datas]));
  523. ui->lab3_4->setText(QString::number(ku[datas]));
  524. break;
  525. case 3:
  526. ui->lineEdit->setText(QString::number(erdu));
  527. ui->lab4_5->setText(QString::number(sum[datas]));
  528. ui->lab4_4->setText(QString::number(ku[datas]));
  529. break;
  530. case 4:
  531. ui->lineEdit->setText(QString::number(erdu));
  532. ui->lab5_5->setText(QString::number(sum[datas]));
  533. ui->lab5_4->setText(QString::number(ku[datas]));
  534. break;
  535. case 5:
  536. ui->lineEdit->setText(QString::number(erdu));
  537. ui->lab6_5->setText(QString::number(sum[datas]));
  538. ui->lab6_4->setText(QString::number(ku[datas]));
  539. break;
  540. case 6:
  541. ui->lineEdit->setText(QString::number(erdu));
  542. ui->lab7_5->setText(QString::number(sum[datas]));
  543. ui->lab7_4->setText(QString::number(ku[datas]));
  544. break;
  545. case 7:
  546. ui->lineEdit->setText(QString::number(erdu));
  547. ui->lab8_5->setText(QString::number(sum[datas]));
  548. ui->lab8_4->setText(QString::number(ku[datas]));
  549. break;
  550. case 8:
  551. ui->lineEdit->setText(QString::number(erdu));
  552. ui->lab9_5->setText(QString::number(sum[datas]));
  553. ui->lab9_4->setText(QString::number(ku[datas]));
  554. break;
  555. case 9:
  556. ui->lineEdit->setText(QString::number(erdu));
  557. ui->lab10_5->setText(QString::number(sum[datas]));
  558. ui->lab10_4->setText(QString::number(ku[datas]));
  559. break;
  560. case 10:
  561. ui->lineEdit->setText(QString::number(erdu));
  562. ui->lab11_5->setText(QString::number(sum[datas]));
  563. ui->lab11_4->setText(QString::number(ku[datas]));
  564. break;
  565. case 11:
  566. ui->lineEdit->setText(QString::number(erdu));
  567. ui->lab12_5->setText(QString::number(sum[datas]));
  568. ui->lab12_4->setText(QString::number(ku[datas]));
  569. break;
  570. }
  571. }
  572. //
  573. void diang::jiajian(int dates)
  574. {
  575. if(sum[dates]==yuan[dates])
  576. {
  577. QMessageBox::information(this,"","已经是所有库存了");
  578. }
  579. sum[dates]+=1;
  580. ku[dates]-=1;
  581. erdu+=much[dates];
  582. switch(dates)
  583. {
  584. case 0:
  585. ui->lineEdit->setText(QString::number(erdu));
  586. ui->lab1_5->setText(QString::number(sum[dates]));
  587. ui->lab1_4->setText(QString::number(ku[dates]));
  588. break;
  589. case 1:
  590. ui->lineEdit->setText(QString::number(erdu));
  591. ui->lab2_5->setText(QString::number(sum[dates]));
  592. ui->lab2_4->setText(QString::number(ku[dates]));
  593. break;
  594. case 2:
  595. ui->lineEdit->setText(QString::number(erdu));
  596. ui->lab3_5->setText(QString::number(sum[dates]));
  597. ui->lab3_4->setText(QString::number(ku[dates]));
  598. break;
  599. case 3:
  600. ui->lineEdit->setText(QString::number(erdu));
  601. ui->lab4_5->setText(QString::number(sum[dates]));
  602. ui->lab4_4->setText(QString::number(ku[dates]));
  603. break;
  604. case 4:
  605. ui->lineEdit->setText(QString::number(erdu));
  606. ui->lab5_5->setText(QString::number(sum[dates]));
  607. ui->lab5_4->setText(QString::number(ku[dates]));
  608. break;
  609. case 5:
  610. ui->lineEdit->setText(QString::number(erdu));
  611. ui->lab6_5->setText(QString::number(sum[dates]));
  612. ui->lab6_4->setText(QString::number(ku[dates]));
  613. break;
  614. case 6:
  615. ui->lineEdit->setText(QString::number(erdu));
  616. ui->lab7_5->setText(QString::number(sum[dates]));
  617. ui->lab7_4->setText(QString::number(ku[dates]));
  618. break;
  619. case 7:
  620. ui->lineEdit->setText(QString::number(erdu));
  621. ui->lab8_5->setText(QString::number(sum[dates]));
  622. ui->lab8_4->setText(QString::number(ku[dates]));
  623. break;
  624. case 8:
  625. ui->lineEdit->setText(QString::number(erdu));
  626. ui->lab9_5->setText(QString::number(sum[dates]));
  627. ui->lab9_4->setText(QString::number(ku[dates]));
  628. break;
  629. case 9:
  630. ui->lineEdit->setText(QString::number(erdu));
  631. ui->lab10_5->setText(QString::number(sum[dates]));
  632. ui->lab10_4->setText(QString::number(ku[dates]));
  633. break;
  634. case 10:
  635. ui->lineEdit->setText(QString::number(erdu));
  636. ui->lab11_5->setText(QString::number(sum[dates]));
  637. ui->lab11_4->setText(QString::number(ku[dates]));
  638. break;
  639. case 11:
  640. ui->lineEdit->setText(QString::number(erdu));
  641. ui->lab12_5->setText(QString::number(sum[dates]));
  642. ui->lab12_4->setText(QString::number(ku[dates]));
  643. break;
  644. }
  645. }
  1. //购物车界面
  2. #include "cede.h"
  3. #include "ui_cede.h"
  4. #include "diang.h"
  5. diang* qing;
  6. //按钮名
  7. QString put[12]={"put1","put2","put3","put4","put5","put6","put7","put8","put9","put10","put11","put12"};
  8. //label名
  9. QString lae[12]={"labt1","labt2","labt3","labt4","labt5","labt6","labt7","labt8","labt9","labt10","labt11","labt12"};
  10. //edix名
  11. QString txt[12]={"edi1","edi2","edi3","edi4","edi5","edi6","edi7","edi8","edi9","edi10","edi11","edi12"};
  12. //(加)按钮
  13. QString an[12]={"an1","an2","an3","an4","an5","an6","an7","an8","an9","an10","an11","an12"};
  14. // 声明一个容器来存储已创建的控件指针
  15. QList<QWidget*> createdWidgets;
  16. cede::cede(QWidget *parent) :
  17. QWidget(parent),
  18. ui(new Ui::cede)
  19. {
  20. ui->setupUi(this);
  21. //显示一个单独的窗口
  22. setWindowFlags(Qt::Window);
  23. //找寻父界面
  24. QWidget* s=parentWidget();
  25. //转化类型
  26. qing = dynamic_cast<diang*>(s);
  27. //连接信号和槽函数
  28. connect(this,&cede::toj,qing,&diang::jajian);
  29. //加法
  30. connect(this,&cede::tos,qing,&diang::jiajian);
  31. }
  32. cede::~cede()
  33. {
  34. delete ui;
  35. }
  36. //
  37. void cede::chuan(QString date, int date2,int infos)
  38. {
  39. QHBoxLayout* horizontalLayout = new QHBoxLayout(this);
  40. qDebug()<<infos;
  41. //创建Qlabel控件
  42. QLabel* labet=new QLabel(date,this);
  43. labet->setObjectName(lae[infos]);
  44. //qDebug()<<labet->objectName();
  45. labet->setFixedSize(100,100);
  46. createdWidgets.append(labet);
  47. //创建QTextEdit
  48. QTextEdit* textEdit = new QTextEdit(QString::number(date2),this);
  49. textEdit->setObjectName(txt[infos]);
  50. textEdit->setFixedSize(50,50);
  51. createdWidgets.append(textEdit);
  52. //创建按钮
  53. QPushButton* jia=new QPushButton("-",this);
  54. jia->setObjectName(put[infos]);
  55. connect(jia,&QPushButton::clicked,this,&cede::jianButtonclick);
  56. jia->setFixedSize(80,50);
  57. createdWidgets.append(jia);
  58. QPushButton* jian=new QPushButton("+",this);
  59. jian->setObjectName(an[infos]);
  60. connect(jian,&QPushButton::clicked,this,&cede::jiaButtonclick);
  61. jian->setFixedSize(50,50);
  62. createdWidgets.append(jian);
  63. //添加到水平布局
  64. horizontalLayout->addWidget(labet);
  65. horizontalLayout->addSpacing(10);
  66. horizontalLayout->addWidget(jia);
  67. horizontalLayout->addSpacing(10);
  68. horizontalLayout->addWidget(textEdit);
  69. horizontalLayout->addSpacing(10);
  70. horizontalLayout->addWidget(jian);
  71. // 获取当前Widget的布局
  72. QVBoxLayout* mainLayout = qobject_cast<QVBoxLayout*>(layout());
  73. // 将水平布局添加到垂直布局
  74. mainLayout->addLayout(horizontalLayout);
  75. }
  76. //
  77. void cede::jianButtonclick()
  78. {
  79. //获取按钮属性
  80. QPushButton* senderButton = qobject_cast<QPushButton*>(sender());
  81. if(senderButton&&senderButton->objectName()==put[0])
  82. {
  83. QTextEdit* textEdit=findChild<QTextEdit*>("edi1");
  84. if(textEdit)
  85. {
  86. QString stc=textEdit->toPlainText();
  87. //转化
  88. int k=stc.toInt();
  89. if(k==0)
  90. {
  91. QMessageBox::information(this,"","已经是最少的了");
  92. qDebug()<<k;
  93. return;
  94. }
  95. k-=1;
  96. textEdit->setText(QString::number(k));
  97. }
  98. emit toj(0);
  99. }
  100. else if(senderButton&&senderButton->objectName()==put[1])
  101. {
  102. QTextEdit* textEdit=findChild<QTextEdit*>("edi2");
  103. if(textEdit)
  104. {
  105. QString stc=textEdit->toPlainText();
  106. //转化
  107. int k=stc.toInt();
  108. if(k==0)
  109. {
  110. QMessageBox::information(this,"","已经是最少的了");
  111. return;
  112. }
  113. k-=1;
  114. textEdit->setText(QString::number(k));
  115. }
  116. emit toj(1);
  117. }
  118. else if(senderButton&&senderButton->objectName()==put[2])
  119. {
  120. QTextEdit* textEdit=findChild<QTextEdit*>("edi3");
  121. if(textEdit)
  122. {
  123. QString stc=textEdit->toPlainText();
  124. //转化
  125. int k=stc.toInt();
  126. if(k==0)
  127. {
  128. QMessageBox::information(this,"","已经是最少的了");
  129. return;
  130. }
  131. k-=1;
  132. textEdit->setText(QString::number(k));
  133. }
  134. emit toj(2);
  135. }
  136. else if(senderButton&&senderButton->objectName()==put[3])
  137. {
  138. QTextEdit* textEdit=findChild<QTextEdit*>("edi4");
  139. if(textEdit)
  140. {
  141. QString stc=textEdit->toPlainText();
  142. //转化
  143. int k=stc.toInt();
  144. if(k==0)
  145. {
  146. QMessageBox::information(this,"","已经是最少的了");
  147. return;
  148. }
  149. k-=1;
  150. textEdit->setText(QString::number(k));
  151. }
  152. emit toj(3);
  153. }
  154. else if(senderButton&&senderButton->objectName()==put[4])
  155. {
  156. QTextEdit* textEdit=findChild<QTextEdit*>(txt[4]);
  157. if(textEdit)
  158. {
  159. QString stc=textEdit->toPlainText();
  160. //转化
  161. int k=stc.toInt();
  162. if(k==0)
  163. {
  164. QMessageBox::information(this,"","已经是最少的了");
  165. return;
  166. }
  167. k-=1;
  168. textEdit->setText(QString::number(k));
  169. }
  170. emit toj(3);
  171. }
  172. else if(senderButton&&senderButton->objectName()==put[5])
  173. {
  174. QTextEdit* textEdit=findChild<QTextEdit*>(txt[5]);
  175. if(textEdit)
  176. {
  177. QString stc=textEdit->toPlainText();
  178. //转化
  179. int k=stc.toInt();
  180. if(k==0)
  181. {
  182. QMessageBox::information(this,"","已经是最少的了");
  183. return;
  184. }
  185. k-=1;
  186. textEdit->setText(QString::number(k));
  187. }
  188. emit toj(3);
  189. }
  190. else if(senderButton&&senderButton->objectName()==put[6])
  191. {
  192. QTextEdit* textEdit=findChild<QTextEdit*>(txt[6]);
  193. if(textEdit)
  194. {
  195. QString stc=textEdit->toPlainText();
  196. //转化
  197. int k=stc.toInt();
  198. if(k==0)
  199. {
  200. QMessageBox::information(this,"","已经是最少的了");
  201. return;
  202. }
  203. k-=1;
  204. textEdit->setText(QString::number(k));
  205. }
  206. emit toj(3);
  207. }
  208. else if(senderButton&&senderButton->objectName()==put[7])
  209. {
  210. QTextEdit* textEdit=findChild<QTextEdit*>(txt[7]);
  211. if(textEdit)
  212. {
  213. QString stc=textEdit->toPlainText();
  214. //转化
  215. int k=stc.toInt();
  216. if(k==0)
  217. {
  218. QMessageBox::information(this,"","已经是最少的了");
  219. return;
  220. }
  221. k-=1;
  222. textEdit->setText(QString::number(k));
  223. }
  224. emit toj(3);
  225. }
  226. else if(senderButton&&senderButton->objectName()==put[8])
  227. {
  228. QTextEdit* textEdit=findChild<QTextEdit*>(txt[8]);
  229. if(textEdit)
  230. {
  231. QString stc=textEdit->toPlainText();
  232. //转化
  233. int k=stc.toInt();
  234. if(k==0)
  235. {
  236. QMessageBox::information(this,"","已经是最少的了");
  237. return;
  238. }
  239. k-=1;
  240. textEdit->setText(QString::number(k));
  241. }
  242. emit toj(3);
  243. }
  244. else if(senderButton&&senderButton->objectName()==put[9])
  245. {
  246. QTextEdit* textEdit=findChild<QTextEdit*>(txt[9]);
  247. if(textEdit)
  248. {
  249. QString stc=textEdit->toPlainText();
  250. //转化
  251. int k=stc.toInt();
  252. if(k==0)
  253. {
  254. QMessageBox::information(this,"","已经是最少的了");
  255. return;
  256. }
  257. k-=1;
  258. textEdit->setText(QString::number(k));
  259. }
  260. emit toj(3);
  261. }
  262. else if(senderButton&&senderButton->objectName()==put[10])
  263. {
  264. QTextEdit* textEdit=findChild<QTextEdit*>(txt[10]);
  265. if(textEdit)
  266. {
  267. QString stc=textEdit->toPlainText();
  268. //转化
  269. int k=stc.toInt();
  270. if(k==0)
  271. {
  272. QMessageBox::information(this,"","已经是最少的了");
  273. return;
  274. }
  275. k-=1;
  276. textEdit->setText(QString::number(k));
  277. }
  278. emit toj(3);
  279. }
  280. else if(senderButton&&senderButton->objectName()==put[11])
  281. {
  282. QTextEdit* textEdit=findChild<QTextEdit*>(txt[11]);
  283. if(textEdit)
  284. {
  285. QString stc=textEdit->toPlainText();
  286. //转化
  287. int k=stc.toInt();
  288. if(k==0)
  289. {
  290. QMessageBox::information(this,"","已经是最少的了");
  291. return;
  292. }
  293. k-=1;
  294. textEdit->setText(QString::number(k));
  295. }
  296. emit toj(3);
  297. }
  298. }
  299. //
  300. void cede::jiaButtonclick()
  301. {
  302. QPushButton* senderButton = qobject_cast<QPushButton*>(sender());
  303. if(senderButton&&senderButton->objectName()==an[0])
  304. {
  305. QTextEdit* textEdit=findChild<QTextEdit*>("edi1");
  306. if(textEdit)
  307. {
  308. QString stc=textEdit->toPlainText();
  309. //转化
  310. int k=stc.toInt();
  311. if(k==10)
  312. {
  313. QMessageBox::information(this,"","已经是最多的了");
  314. return;
  315. }
  316. k+=1;
  317. textEdit->setText(QString::number(k));
  318. }
  319. emit tos(0);
  320. }
  321. else if(senderButton&&senderButton->objectName()==an[1])
  322. {
  323. QTextEdit* textEdit=findChild<QTextEdit*>("edi2");
  324. if(textEdit)
  325. {
  326. QString stc=textEdit->toPlainText();
  327. //转化
  328. int k=stc.toInt();
  329. if(k==10)
  330. {
  331. QMessageBox::information(this,"","已经是最多的了");
  332. return;
  333. }
  334. k+=1;
  335. textEdit->setText(QString::number(k));
  336. }
  337. emit tos(1);
  338. }
  339. else if(senderButton&&senderButton->objectName()==an[2])
  340. {
  341. QTextEdit* textEdit=findChild<QTextEdit*>("edi3");
  342. if(textEdit)
  343. {
  344. QString stc=textEdit->toPlainText();
  345. //转化
  346. int k=stc.toInt();
  347. if(k==10)
  348. {
  349. QMessageBox::information(this,"","已经是最多的了");
  350. return;
  351. }
  352. k+=1;
  353. textEdit->setText(QString::number(k));
  354. }
  355. emit tos(2);
  356. }
  357. else if(senderButton&&senderButton->objectName()==an[3])
  358. {
  359. QTextEdit* textEdit=findChild<QTextEdit*>("edi4");
  360. if(textEdit)
  361. {
  362. QString stc=textEdit->toPlainText();
  363. //转化
  364. int k=stc.toInt();
  365. if(k==10)
  366. {
  367. QMessageBox::information(this,"","已经是最多的了");
  368. return;
  369. }
  370. k+=1;
  371. textEdit->setText(QString::number(k));
  372. }
  373. emit tos(3);
  374. }
  375. else if(senderButton&&senderButton->objectName()==an[4])
  376. {
  377. QTextEdit* textEdit=findChild<QTextEdit*>(txt[4]);
  378. if(textEdit)
  379. {
  380. QString stc=textEdit->toPlainText();
  381. //转化
  382. int k=stc.toInt();
  383. if(k==10)
  384. {
  385. QMessageBox::information(this,"","已经是最多的了");
  386. return;
  387. }
  388. k+=1;
  389. textEdit->setText(QString::number(k));
  390. }
  391. emit tos(3);
  392. }
  393. else if(senderButton&&senderButton->objectName()==an[5])
  394. {
  395. QTextEdit* textEdit=findChild<QTextEdit*>(txt[5]);
  396. if(textEdit)
  397. {
  398. QString stc=textEdit->toPlainText();
  399. //转化
  400. int k=stc.toInt();
  401. if(k==10)
  402. {
  403. QMessageBox::information(this,"","已经是最多的了");
  404. return;
  405. }
  406. k+=1;
  407. textEdit->setText(QString::number(k));
  408. }
  409. emit tos(3);
  410. }
  411. else if(senderButton&&senderButton->objectName()==an[6])
  412. {
  413. QTextEdit* textEdit=findChild<QTextEdit*>(txt[6]);
  414. if(textEdit)
  415. {
  416. QString stc=textEdit->toPlainText();
  417. //转化
  418. int k=stc.toInt();
  419. if(k==10)
  420. {
  421. QMessageBox::information(this,"","已经是最多的了");
  422. return;
  423. }
  424. k+=1;
  425. textEdit->setText(QString::number(k));
  426. }
  427. emit tos(3);
  428. }
  429. else if(senderButton&&senderButton->objectName()==an[7])
  430. {
  431. QTextEdit* textEdit=findChild<QTextEdit*>(txt[7]);
  432. if(textEdit)
  433. {
  434. QString stc=textEdit->toPlainText();
  435. //转化
  436. int k=stc.toInt();
  437. if(k==10)
  438. {
  439. QMessageBox::information(this,"","已经是最多的了");
  440. return;
  441. }
  442. k+=1;
  443. textEdit->setText(QString::number(k));
  444. }
  445. emit tos(3);
  446. }
  447. else if(senderButton&&senderButton->objectName()==an[8])
  448. {
  449. QTextEdit* textEdit=findChild<QTextEdit*>(txt[8]);
  450. if(textEdit)
  451. {
  452. QString stc=textEdit->toPlainText();
  453. //转化
  454. int k=stc.toInt();
  455. if(k==10)
  456. {
  457. QMessageBox::information(this,"","已经是最多的了");
  458. return;
  459. }
  460. k+=1;
  461. textEdit->setText(QString::number(k));
  462. }
  463. emit tos(3);
  464. }
  465. else if(senderButton&&senderButton->objectName()==an[9])
  466. {
  467. QTextEdit* textEdit=findChild<QTextEdit*>(txt[9]);
  468. if(textEdit)
  469. {
  470. QString stc=textEdit->toPlainText();
  471. //转化
  472. int k=stc.toInt();
  473. if(k==10)
  474. {
  475. QMessageBox::information(this,"","已经是最多的了");
  476. return;
  477. }
  478. k+=1;
  479. textEdit->setText(QString::number(k));
  480. }
  481. emit tos(3);
  482. }
  483. else if(senderButton&&senderButton->objectName()==an[10])
  484. {
  485. QTextEdit* textEdit=findChild<QTextEdit*>(txt[10]);
  486. if(textEdit)
  487. {
  488. QString stc=textEdit->toPlainText();
  489. //转化
  490. int k=stc.toInt();
  491. if(k==10)
  492. {
  493. QMessageBox::information(this,"","已经是最多的了");
  494. return;
  495. }
  496. k+=1;
  497. textEdit->setText(QString::number(k));
  498. }
  499. emit tos(3);
  500. }
  501. else if(senderButton&&senderButton->objectName()==an[11])
  502. {
  503. QTextEdit* textEdit=findChild<QTextEdit*>(txt[11]);
  504. if(textEdit)
  505. {
  506. QString stc=textEdit->toPlainText();
  507. //转化
  508. int k=stc.toInt();
  509. if(k==10)
  510. {
  511. QMessageBox::information(this,"","已经是最多的了");
  512. return;
  513. }
  514. k+=1;
  515. textEdit->setText(QString::number(k));
  516. }
  517. emit tos(3);
  518. }
  519. }
  520. //退回
  521. void cede::on_pushButton_clicked()
  522. {
  523. this->hide();
  524. for (QWidget* widget : createdWidgets)
  525. {
  526. // 从布局中移除控件(如果有的话)
  527. if (QLayout* layout = qobject_cast<QLayout*>(widget->parent())) {
  528. layout->removeWidget(widget);
  529. }
  530. // 删除控件
  531. delete widget;
  532. }
  533. //清空容器
  534. createdWidgets.clear();
  535. qing->show();
  536. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/80689
推荐阅读
相关标签
  

闽ICP备14008679号