I want to save a chart as PNG. I'm doing this:

Qt Code:
  1. QChartView* chartView = new QChartView;
  2. chartView->setRenderHint(QPainter::Antialiasing);
  3. chartView->resize(printer.width(), printer.width() * 0.60);
  4.  
  5. QChart* chart = new QChart;
  6. chart->legend()->hide();
  7. chartView->setChart(chart);
  8.  
  9. QDateTimeAxis* xAxis = new QDateTimeAxis;
  10. xAxis->setFormat("dd.MM.yyyy");
  11. chart->addAxis(xAxis, Qt::AlignBottom);
  12.  
  13. QValueAxis* yAxis = new QValueAxis;
  14. chart->addAxis(yAxis, Qt::AlignLeft);
  15.  
  16. QLineSeries* series = new QLineSeries;
  17. series->append(data);
  18. series->setPointsVisible(true);
  19.  
  20. chart->addSeries(series);
  21. series->attachAxis(xAxis);
  22. series->attachAxis(yAxis);
  23.  
  24. QPixmap p = chartView->grab();
  25. 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?