• 大小: 16KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-12
  • 语言: 其他
  • 标签: 基于qt  

资源简介

qt闹钟alarm.zip 源码 等解压后在qt软件中打开即可看到其功能望大家恩能够有所帮助

资源截图

代码片段和文件信息

#include“alarm.h“
#include

Alarm::Alarm(QWidget * parent)
:QDialog(parent)
{
init();
layout();
con();
};

//  ******
//  初始化
//  ******

void Alarm::init()
{
setWindowtitle(“Alarm clock“); //设置标题
setFixedSize(QSize(30080)); //固定大小

timer=new QTimer; //控制lcd的时间刷新
uptimer=new QTimer; //控制对话框上升
dtimer=new QTimer; //控制对话框下降
itimer=new QTimer;

lcdNumber=new QLCDNumber; //显示当前时间
lcdNumber->setFixedSize(QSize(15050)); //固定大小
lcdNumber->setNumDigits(8); //显示八个数字,默认是显示5个数字
lcdNumber->setSegmentstyle(QLCDNumber::Flat); //填充颜色,默认是白色的
lcdNumber->display(QTime::currentTime().toString(“hh:mm:ss“)); //设置格式,还有其他形式的


label=new QLabel(QString::fromLocal8Bit(“闹钟“)); //提示设置下个闹钟
timeEdit=new QTimeEdit; //设置下个闹钟
timeEdit->setDisplayFormat(“hh:mm:ss“);

button=new QPushButton(QString::fromLocal8Bit(“确定“));

trayIcon=new QSystemTrayIcon; //托盘icon
trayIcon->setIcon(QIcon(“./images/qme.ico“));
trayIcon->show();
setWindowIcon(QIcon(“./images/qme.ico“));

restoreAct=new QAction(QString::fromLocal8Bit(“显示“)this);
quitAct=new QAction(QString::fromLocal8Bit(“退出“)this);

trayIconMenu=new QMenu;
trayIconMenu->addAction(restoreAct);
trayIconMenu->addAction(quitAct);

trayIcon->setContextMenu(trayIconMenu);

setWindowFlags(Qt::WindowStaysOnTopHint);
};

//  ****
//  布局
//  ****

void Alarm::layout()
{
QHBoxLayout * rightTopLay=new QHBoxLayout;//
rightTopLay->addWidget(label);
rightTopLay->addWidget(timeEdit);

QHBoxLayout * rightButtomLay=new QHBoxLayout;//
rightButtomLay->addStretch();
rightButtomLay->addWidget(button);

QVBoxLayout * rightLay=new QVBoxLayout;//
rightLay->addLayout(rightTopLay);
rightLay->addLayout(rightButtomLay);
rightLay->addStretch();

QHBoxLayout * main=new QHBoxLayout;//
main->addWidget(lcdNumber);
main->addLayout(rightLay);
setLayout(main);

rect=QApplication::desktop()->rect();//
x=rect.right()-width()-2;//
y=rect.bottom()+30;//
setGeometry(xywidth()height());//
};

//  ****************
//  connect 信号与槽
//  ****************

void Alarm::con()
{
connect(timerSIGNAL(timeout())thisSLOT(clockChange()));
timer->start(1000);

connect(uptimerSIGNAL(timeout())thisSLOT(dialogUp()));
uptimer->start(20);

connect(dtimerSIGNAL(timeout())thisSLOT(down()));
dtimer->start(20);

connect(buttonSIGNAL(clicked())dtimerSIGNAL(timeout()));

connect(buttonSIGNAL(clicked())thisSLOT(mini()));

connect(itimerSIGNAL(timeout())thisSLOT(comToCur()));
itimer->start(20);

connect(restoreActSIGNAL(triggered(bool))uptimerSIGNAL(timeout()));

connect(thisSIGNAL(isCurrentTime())uptimerSIGNAL(timeout()));

connect(itimerSIGNAL(timeout())thisSLOT(comToCur()));
itimer->start(10);

connect(quitActSIGNAL(triggered(bool))thisSLOT(close()));
};

//  **************
//  显示变化的时间
//  **************
void Alarm::clockChange()
{
lcdNumber->display(QTime::currentTime().toString(“hh:mm:ss“));
};


//  **************************
//  闹钟到了,提示框慢慢升起来
//  **************

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2009-11-04 02:55  images\
     文件        2550  2008-06-25 09:36  images\qme.ico
     文件       32988  2009-11-04 09:38  alarm
     文件        4257  2009-11-04 09:39  alarm.cpp
     文件        1302  2009-11-04 09:39  alarm.h
     文件         158  2009-11-04 05:06  main.cpp

评论

共有 条评论