QCustomPlot Discussion and Comments

offscreen renderingReturn to overview

Hi Manu,

I have been using QCustomPlot for a while to show graphs in the UI, but now I need to create some reports with graphs in C++, and am not sure if QCustomPlot is able to create graphs WITHOUT showing them to the user. Can QCustomPlot do offscreen rendering?

I have read "http://qcustomplot.com/index.php/tutorials/specialcases/textdocument", but it says "let's assume our QCustomPlot is ui->plot", and I think that assumption wouldn't hold for me. It means I'd have to show the plot in some UI before I can insert it into QTextDocument and then export it to PDF, correct?

Looking for other options, I've tried QtCharts yesterday, and that only seems to work well when showing the graph for a short time while saving to file, so the user would see many windows flicker when the report is generated.

Vtk seems to have an offscreen rendering solution, but from 20 minutes of googling, it seems its based on mesa/llvmpipe and probably is a support nightmare.

gnuplot-iostreams is a bit dodgy at least on windows.

ChartDirector costs a bit of money, but may work.

Thanks for your help!

yes, use QCustomPlot::toPainter function.

we use it like this:
QPixmap picture(size);
QCPPainter painter(&picture);
QImage img=picture.toImage();

Or just use the savePdf or savePng method. No need to show the plot widget at all.

i dont know about v2, but in v1 , the savePng function didnt work unless you drew it first.

Hi Ian, this isn't the case. Also in QCP 1.x you can use savePng with an invisible QCustomPlot.

Thanks for your great answer everyone! The graphs are indeed beautiful!

I'm embedding them into a QTextDocument (to be PDFed at the end) with paragraphs, tables, images etc, and QTextDocument's QTextCursor- and QText*Format-madness is a total pain to use.

Do you guys have any suggestions to simplify this? I tried QTextDocument::setHtml(), but then its hard to embed graphs using http://qcustomplot.com/index.php/tutorials/specialcases/textdocument since I can't call

QCPDocumentObject::generatePlotFormat(myPlot, 900, 400));

after I have set the whole HTML content.

Is there a better way?