qt4 简单绘图

在继承自QPaintDevice 的类实例上才可以绘图
QPaintDevice Class Reference

Detailed Description

The QPaintDevice class is the base class of objects that can be painted.

A paint device is an abstraction of a two-dimensional space that can be drawn using a QPainter. Its default coordinate system has its origin located at the top-left position. X increases to the right and Y increases downwards. The unit is one pixel.

The drawing capabilities of QPaintDevice are currently implemented by the QWidgetQImageQPixmapQGLPixelBufferQPicture, andQPrinter subclasses.

QMainWindow QDialog的基类都是QWidget,所以可以在其上面绘图

在dialog上绘图
    QPainter painter(this);
    painter.drawRect(0,0,50,50);
在dialog的pixmap上绘图
    QPixmap pix(200,200);  
    pix.fill(Qt::white);   //背景填充为白色  
    QPainter pp(&pix);   //新建QPainter类对象,在pix上进行绘图  
    pp.drawLine(0,0,50,50);     //在pix上的(0,0)点和(50,50)点之间绘制直线  

    QPainter painter(this);      
    painter.drawPixmap(100,100,pix);



所有的绘图设备都有自己的坐标系统,它们互不影响。
http://www.yafeilinux.com/?p=66

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值