在Windows系统上怎么用QT5实现一个时钟桌面
发表于:2026-11-03 作者:千家信息网编辑
千家信息网最后更新 2026年11月03日,这篇文章主要讲解了"在Windows系统上怎么用QT5实现一个时钟桌面",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"在Windows系统上怎么用QT5
千家信息网最后更新 2026年11月03日在Windows系统上怎么用QT5实现一个时钟桌面
这篇文章主要讲解了"在Windows系统上怎么用QT5实现一个时钟桌面",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"在Windows系统上怎么用QT5实现一个时钟桌面"吧!
介绍
这是一个简单的时钟运行界面,项目的结构如图所示,主要包含一个头文件:** analogclock.h **,两个源文件: ** analogclock.cpp main.cpp **.

实现代码
clock.pro
QT += core guigreaterThan(QT_MAJOR_VERSION, 4): QT += widgetsCONFIG += c++11# You can make your code fail to compile if it uses deprecated APIs.# In order to do so, uncomment the following line.#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0SOURCES += \ main.cpp \ analogclock.cppHEADERS += \ analogclock.h# Default rules for deployment.qnx: target.path = /tmp/$${TARGET}/binelse: unix:!android: target.path = /opt/$${TARGET}/bin!isEmpty(target.path): INSTALLS += targetanalogclock.h
#ifndef ANALOGCLOCK_H#define ANALOGCLOCK_H#includeclass AnalogClock : public QWidget{ Q_OBJECTpublic: AnalogClock(QWidget *parent=0);protected: void paintEvent(QPaintEvent *event) override;};#endif // WIDGET_H
analogclock.cpp
#include#include "analogclock.h"AnalogClock::AnalogClock(QWidget *parent) : QWidget(parent){ QTimer *timer = new QTimer(this); //实例一个QTimer的类 connect(timer, SIGNAL(timeout()), this, SLOT(update())); //监控timeout()信号是否发出 //timeout()表示:This signal is emitted when the timer times out. //指计时器发出信号,即下面的延时器发出信号 timer->start(1000);//设置1s的延时 /* *for a function * void QTimer::start(int msec) * Starts or restarts the timer with a timeout interval of msec milliseconds. * If the timer is already running, it will be stopped and restarted. * If singleShot is true, the timer will be activated only once. * 单位是毫秒,表示每一秒设置一个信号发出 */ setWindowTitle(tr("Analog Clock")); //void setWindowTitle(const QString &) resize(200, 200); //初始值大小}void AnalogClock::paintEvent(QPaintEvent *) { /* * * repaint() or update() was invoked, * the widget was obscured and has now been uncovered, or * many other reasons. * * */ static const QPoint hourHand[3] = { QPoint(7, 8), QPoint(-7, 8), QPoint(0, -40) };//用于绘制时针的三角形 static const QPoint minuteHand[3] = { QPoint(7, 8), QPoint(-7, 8), QPoint(0, -60) };//用于绘制分针的三角形 static const QPoint secondHand[3]={ QPoint(7,8), QPoint(-7,8), QPoint(0,-90) };//用于绘制秒针的三角形 QColor hourColor(127, 0, 127); QColor minuteColor(0, 127, 127, 191); //QColor::QColor(int r, int g, int b, int a = 255)a表示透明度 QColor secondColor(220,20,60,100); //为每一个图形绘制颜色及透明度 int side = qMin(width(), height()); //我认为这一句的作用在于找到最小标出,用于坐标系的绘制 QTime time = QTime::currentTime(); qDebug()<
文件
文件夹
时钟
系统
版本
桌面
信号
时针
编译
三角形
分针
画笔
三角
学习
内容
原本
坐标
坐标系
库文件
时间
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
互联网黑科技
科技互联网项目
科技服务与互联网
奇酷互联网科技公司
互联网科技的英文
人人互联网科技是培训
金融科技和互联网金融
互联网科技公司的市场部门
广州慧亚互联网科技怎么样
央行互联网金融科技公司
成都铂石互联网科技做什么的
知域互联网科技有限公司大骗子
未来五年的互联网科技
翼展科技 首家互联网医院
互联网方面的科技前沿
全球科技与互联网公司市值变化
上海万顺科技互联网有限公司招聘
北京军民互联网科技公司
现代科技的标志之一的互联网
中国主要互联网科技公司
互联网科技
互联网最新的科技
深圳艾佳互联网科技
互联网科技英文翻译
互联网养老 桔豆科技
互联网科技有限公司 翻译
高科技互联网发展前景如何
小米互联网科技园入驻
产业互联网科技服务公司
21世纪互联网科技成就