I want to save a chart as PNG. I'm doing this:
QChartView* chartView = new QChartView;
chartView
->setRenderHint
(QPainter::Antialiasing);
chartView->resize(printer.width(), printer.width() * 0.60);
QChart* chart = new QChart;
chart->legend()->hide();
chartView->setChart(chart);
QDateTimeAxis* xAxis = new QDateTimeAxis;
xAxis->setFormat("dd.MM.yyyy");
chart->addAxis(xAxis, Qt::AlignBottom);
QValueAxis* yAxis = new QValueAxis;
chart->addAxis(yAxis, Qt::AlignLeft);
QLineSeries* series = new QLineSeries;
series->append(data);
series->setPointsVisible(true);
chart->addSeries(series);
series->attachAxis(xAxis);
series->attachAxis(yAxis);
p.save("a.png", "PNG");
QChartView* chartView = new QChartView;
chartView->setRenderHint(QPainter::Antialiasing);
chartView->resize(printer.width(), printer.width() * 0.60);
QChart* chart = new QChart;
chart->legend()->hide();
chartView->setChart(chart);
QDateTimeAxis* xAxis = new QDateTimeAxis;
xAxis->setFormat("dd.MM.yyyy");
chart->addAxis(xAxis, Qt::AlignBottom);
QValueAxis* yAxis = new QValueAxis;
chart->addAxis(yAxis, Qt::AlignLeft);
QLineSeries* series = new QLineSeries;
series->append(data);
series->setPointsVisible(true);
chart->addSeries(series);
series->attachAxis(xAxis);
series->attachAxis(yAxis);
QPixmap p = chartView->grab();
p.save("a.png", "PNG");
To copy to clipboard, switch view to plain text mode
The problem is that the axes are not shown. If I show the widget the axes are visible, but even then they are not saved in the PNG...
Any idea how to make them appear in the image?
Bookmarks