当前位置:   article > 正文

QT_day4

QT_day4

1.思维导图

2.

输入闹钟时间格式是小时:分钟

widget.cpp

  1. #include "widget.h"
  2. #include "ui_widget.h"
  3. Widget::Widget(QWidget *parent)
  4. : QWidget(parent)
  5. , ui(new Ui::Widget)
  6. {
  7. ui->setupUi(this);
  8. id = startTimer(1000);
  9. flag=1;
  10. speecher = new QTextToSpeech(this);
  11. player = new QMediaPlayer(this);
  12. player->setMedia(QUrl::fromEncoded("qrc:/picture/凑诗_一千斛担子-一簇奇思妙想的火-原神七七x胡桃同人曲.mp3"));
  13. player->setVolume(50);
  14. this->setWindowFlag(Qt::FramelessWindowHint);
  15. this->setAttribute(Qt::WA_TranslucentBackground);
  16. }
  17. Widget::~Widget()
  18. {
  19. delete ui;
  20. }
  21. void Widget::on_btn1_clicked()
  22. {
  23. if(ui->btn1->text()=="启动")
  24. {
  25. flag=0;
  26. ui->btn1->setText("关闭");
  27. }else
  28. {
  29. flag=1;
  30. ui->btn1->setText("启动");
  31. }
  32. }
  33. void Widget::timerEvent(QTimerEvent *event)
  34. {
  35. if(event->timerId()==id)
  36. {
  37. QTime sys_time = QTime::currentTime();
  38. QString t = sys_time.toString("hh:mm:ss");
  39. QString t2 = sys_time.toString("hh:mm");
  40. ui->lab1->setText(t);
  41. ui->lab1->setAlignment(Qt::AlignCenter);
  42. if(ui->led1->text() == t2 && flag==0)
  43. {
  44. flag=1;
  45. for(int i=0;i<3;i++)
  46. {
  47. speecher->say(ui->lab3->text());
  48. }
  49. player->play();
  50. }
  51. }
  52. }
  53. void Widget::on_pushButton_clicked()
  54. {
  55. this->close();
  56. }

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号