在继承自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 QWidget, QImage, QPixmap, QGLPixelBuffer, QPicture, 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