QPainter类有点类似于MFC中的CDC类。
包含头文件qpainter.h
对要绘制的部件重载虚拟函数paintEvent
protected:
virtual void paintEvent(QPaintEvent*pPaintEvent);
在paintEvent实现中写上绘图代码
{
QPainter p;
p.begin(this);
......绘图
p.end();
}
QPainter常用的成员函数和MFC中常用的成员函数非常类似
例如:drawRect/fillRect/drawLine/drawText/drawPoint/drawPoints/moveTo/lineTo
drawLineSegments/drawPolyline/drawPolygon/drawEllipse/drawArc/drawPixmap...
类似,QPainter可以设置画笔、画刷
例如:
QBrush brush(QColor("white") );
p.setBrush(brush);//在begin之后set
QPen pen(QColor("black"),2,Qt::SolidLine);
p.setPen(pen);
创建一个填充画刷
QBrush brush;
QPixmap pixmap(...);
brush.setPixma( pixmap );
1763

被折叠的 条评论
为什么被折叠?



