本文主要是介绍qt圆环饼状图,非常小的窗口都能显示,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
非常小的窗口都能显示
QT += core gui charts
#include <QtCharts>
using namespace QtCharts;
//创建饼状图
void MainWindow::createpieSewies()
{//饼状图QPieSeries * my_pieSeries = new QPieSeries();//中间圆与大圆的比例my_pieSeries->setHoleSize(0.35);//扇形及数据QPieSlice *pieSlice_running = new QPieSlice();pieSlice_running->setValue(25);//扇形占整个圆的百分比pieSlice_running->setLabel("XXX");pieSlice_running->setLabelVisible();pieSlice_running->setColor(QColor("#4cb9cf"));pieSlice_running->setLabelColor(QColor("#4cb9cf"));pieSlice_running->setBorderColor(QColor("#4cb9cf"));pieSlice_running->setBorderColor(QColor());my_pieSeries->append(pieSlice_running);QPieSlice *pieSlice_noconnect = new QPieSlice();pieSlice_noconnect->setValue(25);pieSlice_noconnect->setLabel("YYY");pieSlice_noconnect->setColor(QColor("#53b666"));pieSlice_noconnect->setLabelColor(QColor("#53b666"));pieSlice_noconnect->setBorderColor(QColor("#53b666"));pieSlice_noconnect->setLabelVisible();//设置标签可见,缺省不可见my_pieSeries->append(pieSlice_noconnect);QPieSlice *pieSlice_idle = new QPieSlice();pieSlice_idle->setValue(50);pieSlice_idle->setLabel("WWW");pieSlice_idle->setLabelVisible();pieSlice_idle->setColor(QColor("#2f89cf"));pieSlice_idle->setLabelColor(QColor("#2f89cf"));pieSlice_idle->setBorderColor(QColor("#2f89cf"));my_pieSeries->append(pieSlice_idle);
// 图表视图QChart *chart = new QChart();chart->setTitle("FFFFF");chart->addSeries(my_pieSeries);chart->setAnimationOptions(QChart::SeriesAnimations);chart->legend()->setAlignment(Qt::AlignBottom);chart->legend()->setBackgroundVisible(false);chart->legend()->setFont(QFont("黑体", 8)) ; // 图例字体chart->setTitleBrush(QColor("#808396"));chart->legend()->setLabelColor(QColor("#808396"));QChartView *chartView = new QChartView();chartView = new QChartView(ui->widget);chartView->setRenderHint(QPainter::Antialiasing);chartView->setRenderHint(QPainter::NonCosmeticDefaultPen);chartView->setChart(chart);ui->gridLayout->addWidget(chartView);
}
这篇关于qt圆环饼状图,非常小的窗口都能显示的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!