参考文章:
https://blog.csdn.net/xiezhongyuan07/article/details/82684118
效果图
void Form::init()
{
QPieSeries *series = new QPieSeries();
//饼图中间空心的大小
series->setHoleSize(0.35);
QPieSlice *slice1 = new QPieSlice(QString("111"), 1);
slice1->setLabelVisible();
slice1->setLabelPosition(QPieSlice::LabelOutside);
slice1->setBrush(QColor(59,160,50));
QPieSlice *slice2 = new QPieSlice(QString(""), 1);
slice2->setLabel(QString("222"));
slice2->setLabelVisible();
slice2->setLabelPosition(QPieSlice::LabelInsideHorizontal);
slice2->setBrush(QColor(59,160,100));
QPieSlice *slice3 = new QPieSlice(QString(""), 1);
slice3->setLabel(QString("333"));
slice3->setLabelVisible();
slice3->setLabelPosition(QPieSlice::LabelOutside);
slice3->setBrush(QColor(59,160,150));
QPieSlice *slice4 = new QPieSlice(QString(""), 1);
slice4->setLabel(QString("444"));
slice4->setLabelVisible();
slice4->setLabelPosition(QPieSlice::LabelOutside);
slice4->setBrush(QColor(255,0,0));
series->append(slice1);
series->append(slice2);
series->append(slice3);
series->append(slice4);
//开始角度
series->setPieStartAngle(100);
//结束角度
series->setPieEndAngle(300);
QChartView *chartView = new QChartView();
chartView->setRenderHint(QPainter::Antialiasing);
//chartView->chart()->setTitle("DonutChart Example");
chartView->chart()->addSeries(series);
chartView->chart()->legend()->hide();
//chartView->chart()->legend()->setAlignment(Qt::AlignRight);
QVBoxLayout *vb = new QVBoxLayout(this);
vb->addWidget(chartView);
this->setLayout(vb);
m_plabel = new QLabel(this);
m_plabel->setFixedSize(40,40);
m_plabel->setText("test");
m_plabel->setStyleSheet(QString("background:transparent;font-family:Mircsoft Yahei;font-size:18px; color:#1564FF; font-weight:bold;"));
m_plabel->move((this->width()-m_plabel->width())/2,
(this->height()-m_plabel->height())/2);
}
void Form::resizeEvent(QResizeEvent* event)
{
m_plabel->move((this->width()-m_plabel->width())/2,
(this->height()-m_plabel->height())/2);
return QWidget::resizeEvent(event);
}