MyImgTest.h:

#ifndef MYIMGTEST_H
#define MYIMGTEST_H

#include
<QWidget>

class
MyImgTest : public QWidget
{
//Q_OBJECT
public:
MyImgTest(QWidget*
parent = 0);
~MyImgTest();
void paintEvent(QPaintEvent *);
};

#endif

MyImgTest.cpp:

#include
"MyImgTest.h"
#include <QPainter>
//#include
<QRect>
//#include <QPointF>
//#include <QLineF>

MyImgTest::MyImgTest(QWidget*
parent) : QWidget(parent)
{
setFixedSize(360,360);
//固定大小
setWindowTitle("Hello
DevDiv!");
}

MyImgTest::~MyImgTest()
{

}

void
MyImgTest::paintEvent(QPaintEvent *)
{
// 画一条直线
QPainter
painter(this); // 创建QPainter一个对象
QPen
pen;

//pen.setStyle(Qt::DashLine);
pen.setColor(Qt::red);
// 设置画笔为黄色
painter.setPen(pen);
// 设置画笔
painter.drawLine(rect().topLeft(),
rect().bottomRight());

//
画一个空心矩形
pen.setColor(Qt::darkRed);
painter.setPen(pen);
painter.drawRect(1,
1, 100, 100); //painter.drawRect(QRect(1, 1, 100, 100));

//
画一个实心矩形
QBrush
bruch(Qt::FDiagPattern); // 画刷
painter.setBrush(bruch);
// 设置画刷
painter.drawRect(QRect(105,
1, 100, 100));

//
画一个多点线
pen.setColor(Qt::black);
painter.setPen(pen);
bruch.setStyle(Qt::NoBrush);
// 将画刷设置成null//fow
what
painter.setBrush(bruch);
static const QPointF points[4] =
{QPointF(210.0, 1), QPointF(220.0, 50.3), QPointF(300, 100.4),
QPointF(260.4, 120.0)};
painter.drawPolyline(points, 4);

//
画多个点
QPointF
pointf[10];
for (int i=0; i<10;
++i)
{
pointf[i].setX(2.0+i*10.0);
pointf[i].setY(130.0);
}
painter.drawPoints(pointf,
10);

// 画多条线
QLineF
linef[5];
for (int j=0; j<5;
++j)
{
linef[j].setP1(QPointF(110.9+j*10,
120.0));
linef[j].setP2(QPointF(120.8+j*12,
200.0));
}
painter.drawLines(linef, 5);

//
画一个多边形
QPolygonF
polygon;
polygon << QPointF(200.0, 120.0) <<
QPointF(230.0, 130.0) << QPointF(260.0, 180.0) <<
QPointF(200.0,
200.0);
bruch.setStyle(Qt::CrossPattern);
painter.setBrush(bruch);
painter.drawPolygon(polygon,
Qt::WindingFill);

// 画一个圆角矩形
QRectF
rectangle(290.0, 110.0, 50,
50);
bruch.setStyle(Qt::SolidPattern);
painter.setBrush(bruch);
painter.drawRoundedRect(rectangle,
20.0, 15.0);

// 画一个QString
painter.drawText(50,
300, "Hello DevDiv!");

}
main.cpp:

#include
<QApplication>
#include "MyImgTest.h"
int
main(int argc,char *argv[])
{
QApplication
app(argc,argv);
MyImgTest* widget = new
MyImgTest();
widget->show();
return app.exec();
}
操作步骤:

1.qmake-qt4
-project

2.qmake-qt4

最新文章

  1. javaweb学习之Servlet开发(二)
  2. mongodb基础用法
  3. poj 3979 分数加减法
  4. uc/os任务创建
  5. C++ Prime:const的引用
  6. [CSS]float&amp;clear浮动
  7. StudentSchema student实例数据库环境搭建
  8. Tomcat7配置数据源(Oracle)
  9. urllib2.URLError: &lt;urlopen error [Errno 104] Connection reset by peer&gt;
  10. Cocos2d-x 3.1.1 Lua实例-AccelerometerTest(重力加速计)
  11. C# 获取与解析枚举类型的 DescriptionAttribute
  12. 记录linux tty的一次软锁排查
  13. sql查询条件为空的另类写法o( ̄▽ ̄)d
  14. Python3 tkinter基础 Menu add_cascade 多级菜单 add_separator 分割线
  15. springboot+cloud 学习(四)Zuul整合Swagger2
  16. Winform 对话框
  17. linux下如何编写shell脚本
  18. uva11235 FrequentValues (ST表)
  19. Nginx 和 PHP 的两种部署方式比较
  20. 【剑指offer】输入一颗二叉树的根节点,求二叉树的深度,C++实现

热门文章

  1. FreeMarker 语法 include 引用模板
  2. js 阻止冒泡
  3. Cache index coloring for virtual-address dynamic allocators
  4. nodejs-函数
  5. Python Study (05)装饰器
  6. HDU 3756
  7. 关于wait notify notifyall的学习心得
  8. UFLDL教程笔记及练习答案五(自编码线性解码器与处理大型图像**卷积与池化)
  9. 杂项-DB-分布式:HBase
  10. centos cmake 升级