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.
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);