1 #include "widget.h"
2 #include "ui_widget.h"
3
4 Widget::Widget(QWidget *parent) :
5 QWidget(parent),
6 ui(new Ui::Widget)
7 {
8 ui->setupUi(this);
9 setGeometry(120,120,600,600);
10 }
11
12 Widget::~Widget()
13 {
14 delete ui;
15 }
16
17 void Widget::paintEvent(QPaintEvent *e)
18 {
19 painter = new QPainter;
20 painter->begin(this);
21 painter->setPen(QPen(Qt::blue,10,Qt::DashDotLine));
22
23 //画刷
24 painter->setBrush(QBrush(Qt::red,Qt::SolidPattern));
25 //画矩形
26 //painter->drawRect(20,20,180,180);
27 //画椭圆
28 //painter->drawEllipse(20,20,190,160);
29 //画点
30 //painter->drawPoint(100,100);
31 //画曲线
32 // painter->drawArc(20,20,210,160,500,1000);
33
34
35 /*
36 case Line: //直线
37 p.drawLine(rect.topLeft(),rect.bottomRight()); break;
38 case Rectangle: //长方形
39 p.drawRect(rect); break;
40 case RoundRect: //圆角方形
41 p.drawRoundRect(rect); break;
42 case Ellipse: //椭圆形
43 p.drawEllipse(rect); break;
44 case Polygon: //多边形
45 p.drawPolygon(points,4); break;
46 case Polyline: //多边线
47 p.drawPolyline(points,4); break;
48 case Points: //点
49 p.drawPoints(points,4); break;
50 case Arc: //弧
51 p.drawArc(rect,startAngle,spanAngle); break;
52 case Path: //路径
53 p.drawPath(path); break;
54 case Text: //文字
55 p.drawText(rect,Qt::AlignCenter,tr("Hello Qt!")); break;
56 case Pixmap: //图片
57 p.drawPixmap(150,150,QPixmap("butterfly.png")); break;
58 default: break;
59
60
61
62
63 painter->drawLine(QPoint(30,30),QPoint(60,180));
64 painter->drawText(this->rect(),Qt::AlignCenter,tr("Hello Qthello haihua!"));
65 painter->drawPixmap(150,150,QPixmap("1.png"));
66 */
67
68 //画线
69 //painter->drawLine(QPoint(30,30),QPoint(60,180));
70 //painter->drawText(this->rect(),Qt::AlignCenter,tr("Hello"));
71 //画图
72 painter->drawPixmap(0,0,QPixmap("1.png"));
73 painter->end();
74 }