widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QPaintEvent>
#include <QTimerEvent>
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = 0);
~Widget();
void paintEvent(QPaintEvent *event);
void timerEvent(QTimerEvent *event);
private:
int sec_count; //秒
int min_count; //分
};
#endif // WIDGET_H
widget.cpp
#include "widget.h"
#include <QPainter>
Widget::Widget(QWidget *parent)
: QWidget(parent),sec_count(0),min_count(0)
{
setFixedSize(800,600);
setWindowTitle("画时钟");
startTimer(1000);
}
Widget::~Widget()
{
}
//重写绘图事件
void Widget::paintEvent(QPaintEvent *event)
{
QPainter p(this); //设置画布为widget
/*
QPoint center(width()/2,height()/2);
p.drawEllipse(center,200,200); //圆心,半径
p.drawLine(center,QPoint(width()/2,height()/2-150)); //y轴向上