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;
}
相关推荐
lsnm39 分钟前
【LINUX网络】HTTP协议基本结构、搭建自己的HTTP简单服务器
linux·运维·服务器·c语言·网络·c++·http
qiuyunoqy1 小时前
list模拟实现
数据结构·c++·list
small_wh1te_coder2 小时前
GCC深度剖析:从编译原理到嵌入式底层实战
汇编·c++·面试·嵌入式·状态模式·c
汤永红2 小时前
week1-[循环嵌套]蛇
数据结构·c++·算法
sqmeeting2 小时前
QT6 如何在Linux Wayland 桌面系统抓屏和分享屏幕
linux·qt
极客BIM工作室3 小时前
谈谈《More Effective C++》的条款30:代理类
java·开发语言·c++
华科云商xiao徐3 小时前
突破Python性能墙:关键模块C++化的爬虫优化指南
c++·爬虫·python
Jooolin4 小时前
【教你一招】反汇编有啥用?
c++·ai编程·汇编语言
xnglan5 小时前
蓝桥杯手算题和杂题简易做法
数据结构·数据库·c++·python·算法·职场和发展·蓝桥杯
melonbo5 小时前
代理模式C++
c++·设计模式·系统安全·代理模式