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;
}
相关推荐
feng_you_ying_li9 小时前
C++复习二,继承与多态
c++
小小de风呀9 小时前
de风——【从零开始学C++】(十一):list的基本使用和模拟实现
开发语言·c++·list
陌路209 小时前
C++高级进阶--夯实进阶基础(1)
开发语言·c++
郝学胜-神的一滴11 小时前
中级OpenGL教程 008:精准控制高光光斑大小与强度
c++·unity·godot·three.js·图形学·opengl·unreal
牢姐与蒯11 小时前
c++数据结构之c++11(一)
数据结构·c++
折戟不必沉沙11 小时前
构造和析构函数能否是虚函数?能否调用虚函数?
c++
-To be number.wan12 小时前
算法日记 | STL- sort排序
c++·算法
不想写代码的星星12 小时前
编译期策略模式:当模板成为策略容器
c++
啦啦啦啦啦zzzz12 小时前
数据结构:平衡二叉树
数据结构·c++·二叉树
玖釉-12 小时前
Vulkan 中 Shader 的 vert、frag、mesh、comp 全面解析:作用、关系、特点与工程实践
开发语言·c++·windows·算法·图形渲染