一.示例
二.源码
//![1]
QPieSeries *series = new QPieSeries();
series->append("Jane", 1);
series->append("Joe", 2);
series->append("Andy", 3);
series->append("Barbara", 4);
series->append("Axel", 5);
//![1]
//![2]
QPieSlice *slice = series->slices().at(1);
slice->setExploded();
slice->setLabelVisible();
slice->setPen(QPen(Qt::darkGreen, 2));
slice->setBrush(Qt::green);
//![2]
//![3]
QChart *chart = new QChart();
chart->addSeries(series);
chart->setTitle("Simple piechart example");
chart->legend()->hide();
//![3]
//![4]
QChartView *chartView = new QChartView(chart);
chartView->setRenderHint(QPainter::Antialiasing);
//![4]
如果需要达到下图效果
自定义类继承QPieSlice,实现hovered的槽,如下。
connect(this, &MySlice::hovered, this, &MySlice::showHighlight);
void MySlice::showHighlight(bool show)
{
setLabelVisible(show);
setExploded(show);
}
|