4.10Qt

widget.h

cpp 复制代码
#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QTimerEvent>
#include <QTimer>
#include <QTime>
#include <QTextToSpeech>
#include <QFont>
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();
    void timerEvent(QTimerEvent *e);

private slots:
    void on_login_clicked();

    void on_close_clicked();

private:
    Ui::Widget *ui;

    int id;
    int id1;

    QTextToSpeech *spe;
};
#endif // WIDGET_H

widget.cpp

cpp 复制代码
#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    spe=new QTextToSpeech(this);
    this->setWindowTitle("闹钟");
    id1=startTimer(1000);
}

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

void Widget::timerEvent(QTimerEvent *e)
{
    if(id1==e->timerId())
    {
        QTime st = QTime::currentTime();
        QString t = st.toString("hh:mm:ss");
        ui->time->setText(t);
        ui->time->setAlignment(Qt::AlignCenter);
        QFont f;
        f.setPointSize(14);
        ui->time->setFont(f);
    }
    if(id==e->timerId())
    {
        QTime st = QTime::currentTime();
        QString t = st.toString("hh:mm:ss");
        ui->time->setText(t);
        ui->time->setAlignment(Qt::AlignCenter);
        QFont f;
        f.setPointSize(14);
        ui->time->setFont(f);
        if(ui->in->text()== t)
        {
            for(int i=0;i<6;i++)
            {
                spe->say(ui->label->text());
            }
        }

    }
}


void Widget::on_login_clicked()
{
    if(ui->login->text()=="启动")
    {
        id=startTimer(1000);
        ui->login->setText("关闭");
    }else
    {
        killTimer(id);
        ui->login->setText("启动");
        spe->stop();
    }
}

void Widget::on_close_clicked()
{
    this->close();
}

ui 样式表

cpp 复制代码
*{
	background-color: rgb(255, 255, 255);
}
QLabel#label{
	border-radius:50px;
	background-color: qlineargradient(spread:pad, x1:0, y1:1, x2:0, y2:0, stop:0 rgba(0, 0, 0, 255), stop:0.05 rgba(14, 8, 73, 255), stop:0.36 rgba(28, 17, 145, 255), stop:0.6 rgba(126, 14, 81, 255), stop:0.75 rgba(234, 11, 11, 255), stop:0.79 rgba(244, 70, 5, 255), stop:0.86 rgba(255, 136, 0, 255), stop:0.935 rgba(239, 236, 55, 255));
	color: rgb(0, 0, 0);
	font: 12pt "楷体";
}
#time{
	background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(228, 167, 255, 255), stop:1 rgba(255, 255, 255, 255));
	color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(9, 41, 4, 255), stop:0.085 rgba(2, 79, 0, 255), stop:0.19 rgba(50, 147, 22, 255), stop:0.275 rgba(236, 191, 49, 255), stop:0.39 rgba(243, 61, 34, 255), stop:0.555 rgba(135, 81, 60, 255), stop:0.667 rgba(121, 75, 255, 255), stop:0.825 rgba(164, 255, 244, 255), stop:0.885 rgba(104, 222, 71, 255), stop:1 rgba(93, 128, 0, 255));
}
#input{
background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(255, 0, 0, 255), stop:0.166 rgba(255, 255, 0, 255), stop:0.333 rgba(0, 255, 0, 255), stop:0.5 rgba(0, 255, 255, 255), stop:0.666 rgba(0, 0, 255, 255), stop:0.833 rgba(255, 0, 255, 255), stop:1 rgba(255, 0, 0, 255));
	color: rgb(0, 0, 0);
font:15pt "等线";
}
QLineEdit{
	background-color: rgb(255, 85, 0);
	color: rgb(0, 255, 255);
	font: 9pt "黑体";
}
QPushButton{
	color: rgb(167, 0, 0,120);
	font: 9pt "隶书";
}
QPushButton#login{
	background-color: rgb(0, 0, 255);
}
#out{
	background-color: rgb(0, 255, 255);
}
#close{
	background-color: rgb(255, 170, 0);
}
QPushButton:hover{	/*鼠标移动*/
	background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(245, 167, 255, 255), stop:1 rgba(255, 255, 255, 255));
	color: rgb(167, 0, 0,120);
	font: 9pt "隶书";
}

QPushButton:pressed{	/*鼠标按下*/
	background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(228, 167, 255, 255), stop:1 rgba(255, 255, 255, 255));
	color: rgb(167, 0, 0,120);
	font: 9pt "隶书";
	padding-top:5px;
	padding-left:5px;
}
相关推荐
樱木Plus12 小时前
深拷贝(Deep Copy)和浅拷贝(Shallow Copy)
c++
blasit2 天前
笔记:Qt C++建立子线程做一个socket TCP常连接通信
c++·qt·tcp/ip
肆忆_3 天前
# 用 5 个问题学懂 C++ 虚函数(入门级)
c++
不想写代码的星星4 天前
虚函数表:C++ 多态背后的那个男人
c++
端平入洛5 天前
delete又未完全delete
c++
端平入洛6 天前
auto有时不auto
c++
哇哈哈20217 天前
信号量和信号
linux·c++
多恩Stone7 天前
【C++入门扫盲1】C++ 与 Python:类型、编译器/解释器与 CPU 的关系
开发语言·c++·人工智能·python·算法·3d·aigc
蜡笔小马7 天前
21.Boost.Geometry disjoint、distance、envelope、equals、expand和for_each算法接口详解
c++·算法·boost
超级大福宝7 天前
N皇后问题:经典回溯算法的一些分析
数据结构·c++·算法·leetcode