QT里没有相应统计图形的绘制组件
只有手工自己画
效果如图
void aaq::paintEvent( QPaintEvent* ev )
{
QPainter painter(this);
// 去除画笔
painter.setPen(Qt::NoPen);
// 设置反锯齿
painter.setRenderHint(QPainter::Antialiasing); //******************************************** 圆饼图 *****************************************//
if()
{
// 顶层圆面
QRectF rect_top(10.0, 20.0, 280.0, 160.0);
// 底层圆面
QRectF rect_bottom(10.0, 60.0, 280.0, 160.0);
// 中间矩形
QRectF rect_midd(10.0, 100.0, 280.0, 40.0); // 扇形起始角度
int startAngle = * ;
// 扇形覆盖范围
int spanAngle = * ; painter.setBrush(QColor(,,,));
// 绘制底层圆面
painter.drawEllipse(rect_bottom);
// 绘制中间矩形
painter.drawRect(rect_midd); painter.setBrush(QColor(Qt::darkYellow));
// 绘制底层扇形
painter.drawPie(rect_bottom, startAngle, spanAngle); // 扇形的弦与弧的交点
double pi = 3.1415926;
double dx1 = rect_top.width() * 0.5 * cos( * pi / );
double dy1 = rect_top.height() * 0.5 * sin( * pi / ); double dx2 = rect_top.width() * 0.5 * cos( * pi / );
double dy2 = rect_top.height() * 0.5 * sin( * pi / ); // 求交点的坐标值
QPointF posBackCenter = QPointF(rect_top.center());
double dX1 = posBackCenter.x() + dx1 + 0.5;
double dY1 = posBackCenter.y() - dy1 + 0.5; double dX2 = posBackCenter.x() + dx2 + 0.5;
double dY2 = posBackCenter.y() - dy2 + 0.5; // 记录交点
QPointF topLeft = QPointF(dX1, dY1);
QPointF bottomRight = QPointF(dX2, dY2) + QPointF(,);
QPointF bottomLeft = topLeft + QPointF(,);
painter.setBrush(QColor(Qt::darkYellow)); // 绘制连接扇形的区域
QPolygonF path;
path << topLeft << QPointF(dX2,dY2) << bottomRight << bottomLeft;
painter.drawPolygon(path); // 绘制顶层圆面
painter.setBrush(QColor(,,,));
painter.drawEllipse(rect_top); // 绘制顶层扇形
painter.setBrush(QColor(Qt::yellow));
painter.drawPie(rect_top, startAngle, spanAngle);
} QWidget::paintEvent(ev);
}
http://blog.csdn.net/u013007900/article/details/50058837