QT DAY 4

#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    this->setStyleSheet("background-color: pink");

    this->setFixedSize(540, 420);

    time_label = new QLabel(this);
    time_label->resize(280, 100);
    time_label->setStyleSheet("background-color: white");
    time_label->move(50, 25);

    timer_id = this->startTimer(1000);

    time_lineedit = new QLineEdit(this);
    time_lineedit->resize(140, 60);
    time_lineedit->setStyleSheet("background-color: white");
    time_lineedit->move(time_label->x() + 300, time_label->y());
    time_lineedit->setFont(QFont("Consolas", 14));
    time_lineedit->setPlaceholderText("小时:分钟:秒数");

    start_btn = new QPushButton("启动", this);
    start_btn->resize(60, 30);
    start_btn->move(time_label->x() + 300, time_label->y() + 70);
    start_btn->setStyleSheet("background-color: white");
    connect(start_btn, &QPushButton::clicked, this, &Widget::start_btn_clicked);


    stop_btn = new QPushButton("停止", this);
    stop_btn->resize(60, 30);
    stop_btn->move(start_btn->x() + 80, time_label->y() + 70);
    stop_btn->setStyleSheet("background-color: white");
    stop_btn->setEnabled(false);
    connect(stop_btn, &QPushButton::clicked, this, &Widget::stop_btn_clicked);

    text_edit = new QTextEdit(this);
    text_edit->resize(440, 280);
    text_edit->setStyleSheet("background-color: white");
    text_edit->move(50, time_label->y() + 110);
    text_edit->setFont(QFont("Consolas", 20));

    speecher = new QTextToSpeech(this);

    timer = new QTimer(this);
    connect(timer, &QTimer::timeout, this, &Widget::timeout_slot);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::timerEvent(QTimerEvent *event)
{
    if(event->timerId() == timer_id)
    {
//        static int num = 0;
//        ui->eventlabel->setNum(++num);
        sys_dt = QDateTime::currentDateTime();
        time_label->setText(sys_dt.toString("yyyy-MM-dd h:m:s"));
        time_label->setAlignment(Qt::AlignCenter);    //标签文本对齐方式
        time_label->setFont(QFont("Consolas", 18));
    }
}

void Widget::start_btn_clicked()
{
    stop_btn->setEnabled(true);
    text_edit->setEnabled(false);
    time_lineedit->setEnabled(false);
    start_btn->setEnabled(false);
    timer->start(1000);
}

void Widget::stop_btn_clicked()
{
    start_btn->setEnabled(true);
    text_edit->setEnabled(true);
    time_lineedit->setEnabled(true);
    stop_btn->setEnabled(false);
    timer->stop();
}

void Widget::timeout_slot()
{
    QTime sys_time = QTime::currentTime();
    QString time = sys_time.toString("h:m:s");
    if(time == time_lineedit->text())
    {
        speecher->say(text_edit->toPlainText());
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值