头文件:
#ifndef DIGICLOCK_H
#define DIGICLOCK_H
#include <QLCDNumber>
class DigClock : public QLCDNumber
{
Q_OBJECT
public:
DigClock(QWidget *parent=0);
void mousePressEvent(QMouseEvent *);
void mouseMoveEvent(QMouseEvent *);
public slots:
void showTime(); //显示当前时间
private:
QPoint dragPosition; //保存鼠标相对电子时钟窗体左上角的偏移值
bool showColon; //用于显示时间时是否显示“:”
};
#endif // DIGICLOCK_H
源码:
#include "digclock.h"
#include <QTimer>
#include <QTime>
#include <QMouseEvent>
DigClock::DigClock(QWidget *parent)
:QLCDNumber(parent)
{
QPalette p=palette();
p.setColor(QPalette::Window,Qt::blue);
setPalette(p);
setWindowFlags(Qt::FramelessWindowHint);
setWindowOpacity(0.5);
QTimer *timer=new QTimer(this);
connect(time