1、正常显示系统时间,当给定时间和给定输出内容后,点击启动使得不可更改时间和内容,启动按钮不可用,只用按了取消按钮后才可以使用。()
.cpp(功能)
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
timer = new QTimer(this);
// 启动定时器
timer_id = startTimer(1000);
ui->Tbtn1->setEnabled(true);
ui->Tlb->setEnabled(true);
ui->Ttxt->setEnabled(true);
ui->Tbtn2->setEnabled(false);
}
Widget::~Widget()
{
delete ui;
}
void Widget::timerEvent(QTimerEvent *event)
{
if (event->timerId() == timer_id) {
// 获取系统的时间,并将时间进行显示
QDateTime time = QDateTime::currentDateTime();
QString str_time = time.toString("yyyy-MM-dd hh:mm:ss");
ui->Tlab->setText(str_time);
timer_id = startTimer(1000);
if(ui->Tbtn1->isEnabled() == false)
{
QTextToSpeech *speech = new QTextToSpeech(this);//实例化一个语音播报者
// QString text = ui->Ttxt->toPlainText();//获取文本
if(time.toString("hh:mm") == ui->Tlb->text())
{
speech->say(ui->Ttxt->toPlainText());//将给定的文本读出来
}
}
}
}
void Widget::on_Tbtn1_clicked()
{
QMessageBox box(
QMessageBox::NoIcon,
"设置闹钟",
"是否确认将此时间设定成闹钟?是否将此内容设定成闹钟的播报内容?",
QMessageBox::Yes|QMessageBox::No,
this);
if (box.exec() == QMessageBox::Yes)
{
ui->Tbtn1->setEnabled(false);
ui->Tbtn2->setEnabled(true);
ui->Ttxt->setReadOnly(true);
ui->Tlb->setReadOnly(true);
}
// speech->
}
void Widget::on_Tbtn2_clicked()
{
QMessageBox box(
QMessageBox::NoIcon,
"设置闹钟",
"是否取消此闹钟?",
QMessageBox::Yes|QMessageBox::No,
this);
if (box.exec() == QMessageBox::Yes)
{
ui->Tbtn1->setEnabled(true);
ui->Tbtn2->setEnabled(false);
ui->Ttxt->setReadOnly(false);
ui->Tlb->setReadOnly(false);
QMessageBox box(
QMessageBox::NoIcon,
"清空",
"是否清空时间和内容?",
QMessageBox::Yes|QMessageBox::No,
this);
if (box.exec() == QMessageBox::Yes)
{
ui->Tlb->clear();
ui->Ttxt->clear();
}
}
}