程序
继承QLCDNumber类重新定义鼠标点击和鼠标移动事件。
//.h
#ifndef DIGICLOCK_H
#define DIGICLOCK_H
#include<QLCDNumber>
class DigiClock : public QLCDNumber
{
Q_OBJECT
public:
DigiClock(QWidget*parent=0);
void mousePressEvent(QMouseEvent*);//鼠标点击时间
void mouseMoveEvent(QMouseEvent*);//鼠标移动事件
public slots:
void showTime();//时间显示函数
private:
QPoint dragPosition;//保存鼠标点相对电子时钟窗体左上角的偏移值
bool showColon;//用于显示时间时是否显示“:”
};
#endif // DIGICLOCK_H
//.cpp
#include