
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = 0);
~Widget();
protected:
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void paintEvent(QPaintEvent *event);
private:
QPoint dragPosition;
QPixmap pix;
bool flag=true;
};
#endif
#include "widget.h"
#include <QMouseEvent>
#include <QPainter>
#include <QPixmap>
#include <QBitmap>
#include <QLCDNumber>
#include <QPushButton>
#include <QTime>
#include <QTimer>
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
pix.load(":/mm.png",0,Qt::AvoidDither | Qt::ThresholdDither | Qt::ThresholdAlphaDither);
resize(pix.size());
setMask(QBitmap(pix.mask()));
QLCDNumber *lcdnum=new QLCDNumber(this);
lcdnum->setDigitCount(8);
lcdnum->setMode(QLCDNumber::Dec);
lcdnum->setSegmentStyle(QLCDNumber::Flat);
lcdnum->setStyleSheet("color:black;background-color: transparent;");
QTime tim=QTime::currentTime();
QString str=tim.toString("hh:mm:ss");
lcdnum->display(str);
QTimer *timer=new QTimer(this);
timer->start(1000);
connect(timer,&QTimer::timeout,[=](){
QTime tim=QTime::currentTime();
QString str=tim.toString("hh:mm:ss");
str=tim.toString("hh:mm:ss");
if(this->flag){
this->flag=false;
}else{
QString a=str.mid(6);
if(a=="00"){
str.replace(2,1," ");
}
str.replace(5,1," ");
this->flag=true;
}
lcdnum->display(str);
});
lcdnum->resize(200,80);
lcdnum->move(this->width()*0.5-130,this->height()*0.5+50);
}
Widget::~Widget()
{
}
void Widget::mousePressEvent(QMouseEvent *event){
if(event->button()==Qt::LeftButton){
this->dragPosition=event->globalPos()-frameGeometry().topLeft();
event->accept();
}
if(event->button()==Qt::RightButton){
this->close();
}
}
void Widget::mouseMoveEvent(QMouseEvent *event){
if(event->buttons() & Qt::LeftButton){
this->move(event->globalPos()-this->dragPosition);
event->accept();
}
}
void Widget::paintEvent(QPaintEvent *event){
QPainter painterr(this);
painterr.drawPixmap(0,0,pix);
}
