闹钟
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
ui->speaklab->setText("风带来故事的种子,时间使其发芽!");
ui->timeline->setPlaceholderText("小时:分钟:秒钟");
// if(ui->systlab->text()==ui->timeline->text())
// {
// ui->speaklab->setText("好好学习,天天向上!");
// }
speaker =new QTextToSpeech(this);
this->setWindowFlag(Qt::FramelessWindowHint);
this->setAttribute(Qt::WA_TranslucentBackground);
}
Widget::~Widget()
{
delete ui;
}
void Widget::timerEvent(QTimerEvent *e)
{
if(e->timerId()==id)
{
QTime sys_time=QTime::currentTime();
QString s=sys_time.toString("hh::mm::ss");
ui->systlab->setText(s);
ui->systlab->setAlignment(Qt::AlignCenter);
if(ui->timeline->text()==s)
{
ui->speaklab->setText("好好学习,天天向上!");
for(int i=0;i<5;i++)
{
speaker->say(ui->speaklab->text());
}
}
}
}
void Widget::on_staendbut_clicked()
{
if(ui->staendbut->text()=="启动")
{
//启动计时器
ui->staendbut->setText("暂停");
id=startTimer(1000); //每阁一秒,执行一次
}
else
{
killTimer(id);
ui->staendbut->setText("启动");
}
}