Qt画饼图
时间:2011-04-07 来源:ervid
PaintArea::PaintArea()
{
scale=1;//初始化scale
image=QImage(800,600,QImage::Format_RGB32);
backColor=qRgb(255,255,255);//设置背景色为白色
image.fill(backColor);
paint(image);
}
void PaintArea::paintEvent(QPaintEvent *)
{
QPainter paint(this);
paint.scale(scale,scale);
paint.drawImage(0,0,image);
}
void PaintArea::paint(QImage &image)
{
QPainter painter(&image);
// painter.drawLine(0,0,400,400);
painter.setBrush(Qt::red);
painter.setPen(Qt::NoPen);
// painter.drawPie(0,0,30,30,0,90*16);
painter.drawPie(50,50,100,100,0,90*16*6/10);//6为男,10为总个数
painter.setBrush(Qt::blue);
painter.drawPie(50,50,100,100,90*16*6/10,360*16-90*16*6/10);
painter.setPen(Qt::blue);
painter.drawText(10,10,tr("男"));
painter.setPen(Qt::red);
painter.drawText(10,20,tr("女"));
}
相关阅读 更多 +