




已阅读5页,还剩3页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
精品文档本程序基于QWidget实现,可以动态显示钟表,并且可以添加铃声头文件widget.h代码如下:#ifndef WIDGET_H#define WIDGET_H#include #include#include#include#include#include#include#include#include#include#include#include#include#include#include#includenamespace Ui class Widget;class Widget : public QWidget Q_OBJECTpublic: explicit Widget(QWidget *parent = 0); Widget();signals: void isCurrentTime();private: Ui:Widget *ui; void init(); void layout(); void con(); QLCDNumber *lcdNumber; QLabel *label; QTimeEdit *timeEdit; QPushButton *button; QTimer *timer; QTimer *uptimer; QTimer *dtimer; QTimer *itimer; QRect rect; int x; int y; double du; QSystemTrayIcon *trayIcon; QAction *restoreAct; QAction *quitAct; QMenu *trayIconMenu;private slots: void clockChange(); void dialogUp(); void mini(); void down(); void comToCur();protected: void closeEvent(QCloseEvent *e);#endif / WIDGET_H源文件widget.cpp代码如下:#include widget.h#include ui_widget.h#include#include#includeWidget:Widget(QWidget *parent) : QWidget(parent), ui(new Ui:Widget) ui-setupUi(this); init(); layout(); con(); void Widget:init() setWindowTitle(我的闹钟); setFixedSize(300,80); timer=new QTimer; uptimer=new QTimer; dtimer=new QTimer; itimer=new QTimer; lcdNumber=new QLCDNumber; lcdNumber-setFixedSize(150,50); lcdNumber-setDigitCount(12); lcdNumber-setSegmentStyle(QLCDNumber:Flat); lcdNumber-display(QTime:currentTime().toString(hh:mm:ss:zzz); label=new QLabel(闹钟); timeEdit=new QTimeEdit; timeEdit-setDisplayFormat(hh:mm:ss); button=new QPushButton(确定); trayIcon=new QSystemTrayIcon; trayIcon-setIcon(QIcon(:/new/prefix1/clock.ico); trayIcon-show(); setWindowIcon(QIcon(:/new/prefix1/clock.ico); restoreAct=new QAction(显示,this); quitAct=new QAction(退出,this); trayIconMenu=new QMenu; trayIconMenu-addAction(restoreAct); trayIconMenu-addAction(quitAct); trayIcon-setContextMenu(trayIconMenu); setWindowFlags(Qt:WindowStaysOnTopHint);void Widget:layout() QHBoxLayout *rightTopLay=new QHBoxLayout; rightTopLay-addWidget(label); rightTopLay-addWidget(timeEdit); QHBoxLayout *rightButtonLay=new QHBoxLayout; rightButtonLay-addStretch(); rightButtonLay-addWidget(button); QVBoxLayout *rightLay=new QVBoxLayout; rightLay-addLayout(rightTopLay); rightLay-addLayout(rightButtonLay); rightLay-addStretch(); QHBoxLayout *m=new QHBoxLayout; m-addWidget(lcdNumber); m-addLayout(rightLay); setLayout(m); QDesktopWidget *p=new QDesktopWidget; p=QApplication:desktop();/ rect=p-rect(); x=rect.right()-width()-2;/ y=rect.bottom()+30;/ setGeometry(x,y,width(),height();void Widget:con() connect(timer,SIGNAL(timeout(),this,SLOT(clockChange(); timer-start(1); connect(uptimer,SIGNAL(timeout(),this,SLOT(dialogUp(); uptimer-start(20); connect(dtimer,SIGNAL(timeout(),this,SLOT(down(); dtimer-start(20); connect(button,SIGNAL(clicked(bool),dtimer,SIGNAL(timeout(); connect(button,SIGNAL(clicked(bool),this,SLOT(mini(); connect(itimer,SIGNAL(timeout(),this,SLOT(comToCur(); itimer-start(20); connect(restoreAct,SIGNAL(triggered(bool),uptimer,SIGNAL(timeout(); connect(this,SIGNAL(isCurrentTime(),uptimer,SIGNAL(timeout(); connect(itimer,SIGNAL(timeout(),this,SLOT(comToCur(); itimer-start(20); connect(quitAct,SIGNAL(triggered(bool),this,SLOT(close();void Widget:clockChange() lcdNumber-display(QTime:currentTime().toString(hh:mm:ss:zzz);void Widget:dialogUp() show(); uptimer-start(20); if(y=rect.bottom()-height()-50) y-=2; else uptimer-stop(); setGeometry(x,y,width(),height();void Widget:down() dtimer-start(20); if(ystop(); setGeometry(x,y,width(),height();void Widget:mini() hide();void Widget:closeEvent(QCloseEvent *e) QMessageBox:information(0,退出,您确定要退出吗?);void Widget:comToCur() if(QVariant(QTime:currentTi
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025北京大学党委办公室校长办公室招聘模拟试卷及答案详解参考
- 班组安全建设培训课件
- 2025辽宁阜新能源控股集团所属阜矿集团招聘90人模拟试卷及答案详解(名师系列)
- 充电服务费监管-洞察与解读
- 2025年4月四川成都市成华区中医医院招聘编外人员3人考前自测高频考点模拟试题及答案详解(名校卷)
- 2025广西柳州市港航发展中心招聘编外合同制工作人员1人模拟试卷及参考答案详解一套
- 2025江苏南京市玄武区人民政府玄武门街道办事处招聘编外人员5人考前自测高频考点模拟试题及答案详解一套
- 太赫兹能量收集-洞察与解读
- 2025年牡丹江绥芬河市公开招聘公益性岗位工作人员20人(第一批)考前自测高频考点模拟试题附答案详解
- 2025春季江淮汽车校园招聘正式启动模拟试卷完整参考答案详解
- 农业银行笔试题库及答案
- 医疗放射防护培训课件
- 教师岗位聘任申请书模板合集
- 2025年贵州省毕节市辅警招聘考试题库及答案
- 巴中市恩阳区2025年专项招聘卫生专业技术人员的(50人)考试参考题库及答案解析
- 2025-2026学年人教版(2024)小学体育与健康二年级全一册《防溺水知危险》教学设计
- 出海作业安全培训课件
- 9.2 排鱼求数 课件 北京版数学三年级上册
- GB/T 4699.2-2025铬铁、硅铬合金、氮化铬铁和高氮铬铁铬含量的测定过硫酸铵氧化滴定法和电位滴定法
- 监理现场管理知识培训课件
- GJB3206B-2022技术状态管理
评论
0/150
提交评论