QT上LCD窗口显示系统时间
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#ifndef WIDGET_H
#define WIDGET_H
#include
#include
#include
class Widget : public QLCDNumber
{
Q_OBJECT
public:
Widget(QWidget *parent = 0);
~Widget();
public slots:
void showTime();
protected:
void mouseMoveEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *event);
private:
QPoint lastPos;
bool showCap;
};
#endif // WIDGET_H
***************************
#include "widget.h"
#include
#include
#include
Widget::Widget(QWidget *parent)
: QLCDNumber(parent)
{
QPalette p=this->palette();
p.setColor(QPalette::Background,Qt::blue);
this->setPalette(p);
this->setWindowFlags(Qt::FramelessWindowHint);
this->resize(300,150);
this->setWindowOpacity(0.5);
this->setDigitCount(8);
this->setToolTip(QString("当前系统时间"));
QTimer *timer=new QTimer;
timer->setInterval(500);
connect(timer,SIGNAL(timeout()),
this,SLOT(showTime()));
timer->start();
showCap=false;
}
Widget::~Widget()
{
}
void Widget::mouseMoveEvent(QMouseEvent *event)
{
int dx=event->globalX()-lastPos.x();
int dy=event->globalY()-lastPos.y();
lastPos=event->globalPos();
move(this->x()+dx,this->y()+dy);
}
void Widget::mousePressEvent(QMouseEvent *event)
{
if (event->button()==Qt::RightButton)
{
this->close();
}
if (event->button()==Qt::LeftButton)
{
lastPos=event->globalPos();
}
}
void Widget::showTime()
{
QTime time=QTime::currentTime();
QString curTime;
if (showCap)
{
curTime=time.toString("hh:mm:ss");
showCap=false;
}
else
{
curTime=time.toString("hh:mm ss");
showCap=true;
}
this->display(curTime);
}