static int ax[320]; //数组不能直接用X[],Y[]
static int ay[320];
void Form1::init()
{
int i;
for (i=-160;i<161;i++)
{
ax[i+159]=i+160; //X[-1]作用是把两副图联系起来,中间无间格点
ay[i+159]=int (160-160*sin(3.14*i/80));
ax[i+160]=i+161;
ay[i+160]=int (160-160*sin(3.14*(i+1)/80));
}
flag=0;
}
void Form1::draw()
{
int i;
//int a,b,c,d;//用于绘制网格,坐标轴的临时变量
QPixmap pix(320,320);
QPainter p(&pix);
pix.fill(red);//Fills the pixmap with the color fillColor
p.setPen(blue); //绘制坐标轴
p.drawLine(0,160,320,160); //横线
p.drawLine(315,155,320,160);//箭头
p.drawLine(315,165,320,160);
p.drawLine(160,0,160,320);
p.drawLine(155,5,160,0);
p.drawLine(165,5,160,0);
p.setPen(yellow);
for (i=0;i<320;i++)
{
p.drawLine(ax,ay,ax[i+1],ay[i+1]);
}
p.end();
p.begin(textLabel3);
p.drawPixmap(0,0,pix);//通过把pix的一部分复制到绘制设备中,在(x, y)绘制一个像素映射
p.end();
}
截取的部分程序,可以参考一下.