#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
this->resize(1000,600);
this->setFixedSize(1000,600);
//设置按钮大小位置完成
btn1 = new QPushButton("启动",this);
btn2 = new QPushButton("关闭",this);
lab = new QLabel(this);
line = new QLineEdit(this);
text = new QTextEdit(this);
lab->resize(450,150);
line->resize(300,70);
btn1->resize(130,50);
btn2->resize(130,50);
text->resize(800,300);
text->move(100,250);
lab->move(100,50);
line->move(600,50);
btn1->move(600,150);
btn2->move(770,150);
//设置按钮的美化
lab->setStyleSheet("font-size:60px");
lab->setAlignment(Qt::AlignCenter);
//连接函数
connect(btn1,&QPushButton::clicked,this,&Widget::btn1_slot);
connect(btn2,&QPushButton::clicked,this,&Widget::btn2_slot);
connect(line,&QLineEdit::editingFinished,this,&Widget::line_slot);
}
Widget::~Widget()
{
delete ui;
}
void Widget::btn1_slot()
{
tid = this->startTimer(1000);
}
void Widget::btn2_slot()
{
this->killTimer(tid);
}
void Widget::line_slot()
{
alarm_Time = line->text();
}
void Widget::timerEvent(QTimerEvent *event){
if(event->timerId()==tid){
QDateTime sysDateTime = QDateTime::currentDateTime();
QString DateTime = sysDateTime.toString("hh:mm:ss,a");
lab->setText(DateTime);
if(DateTime == alarm_Time){
QTextToSpeech *speecher;
speecher = new QTextToSpeech(this);
QString msg = text->toPlainText();
speecher->say(msg);
}
}
}
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
}
Widget::~Widget()
{
delete ui;
}
void Widget::timerEvent(QTimerEvent *event){
QDateTime sysDateTime = QDateTime::currentDateTime();
DateTime_h = sysDateTime.toString("hh");
DateTime_m = sysDateTime.toString("mm");
DateTime_s = sysDateTime.toString("ss");
H = DateTime_h.toInt()%12;
M = DateTime_m.toInt();
S = DateTime_s.toInt();
deg_s = S*6;
deg_m = M*6;
deg_h = H*6;
this->update();
}
void Widget::paintEvent(QPaintEvent *event){
//画背景的画家
QPainter paint_1(this);
QPen pen_1(QColor("pink"));
pen_1.setWidth(10);
paint_1.setPen(pen_1);
QPoint point(this->width()/2,this->height()/2);
QPoint zero(0,0);
paint_1.translate(point);
paint_1.drawEllipse(zero,200,200);
//画三针的画家
//时针
QPainter paint_2(this);
//更改画家坐标系
paint_2.translate(point);
QPen pen_2(QColor("red"));
pen_2.setWidth(15);
paint_2.setPen(pen_2);
QPoint point_h(point.x(),point.y()-50);
paint_2.rotate(deg_h);
paint_2.drawLine(0,0,0,50);
//分针
pen_2.setColor(QColor("blue"));
pen_2.setWidth(10);
paint_2.setPen(pen_2);
QPoint point_m(point.x(),point.y()-100);
paint_2.rotate(deg_m);
paint_2.drawLine(0,0,0,100);
//秒针
pen_2.setColor(QColor("green"));
pen_2.setWidth(5);
paint_2.setPen(pen_2);
QPoint point_s(point.x(),point.y()-150);
paint_2.rotate(deg_s);
paint_2.drawLine(0,0,0,150);
}