View Full Version : Export Plot Results to PDF
theofthe
17th October 2014, 23:22
In my application, I have multiple tabs, in each tab, there is a plot diagram (QwtPlot object). I need to export the plot diagram inside each tab into a single pdf file. Is there any "append" option in QwtPlotRenderer class I can use? If not, is there any file format supported by qwt?
Uwe
18th October 2014, 16:05
A convenient way for one plot to one file is QwtPlotRenderer::renderDocument().
QwtPlotRenderer renderer;
for( int i = 0; i < numTabs; i++ )
{
renderer.renderDocument( plot(i), fileName(i), "pdf", QSizeF( 300, 200 ), 85 );
// renderer.renderDocument( plot(i), fileName(i), QSizeF( 300, 200 ), 85 ); // guesses the format from the fileName extension
}
As PDF ( like SVG ) is a vector graphics format the resolution parameter only matters, when your plot contains raster graphics ( f.e. a spectrogram ). For raster graphic formats ( see QImageWriter::supportedImageFormats() ) a higher resolution means higher quality.
QwtPlotRenderer offers several convenience methods how to set up a QPainter, but in the end they all call:
virtual void QwtPlotRenderer::render( QwtPlot *, QPainter *, const QRectF &rect ) const;
So when none of the convenience methods match your use case you can always setup your painter individually and call QwtPlotRenderer::render() from application code.
Examples might be if you want to render several plots to the same page, or create a PDF document for all plots, where you want to have each plot on a single page.
When trying to set up the painter in application code looking at the implementation of QwtPlotRenderer ( qwt_plot_renderer.cpp ) might help.
Uwe
theofthe
30th October 2014, 04:12
Thanks again Uwe. Your suggestion works fine.
Btw, may be if QwtPlotRenderer class could provide the append function and page adjustment functions in the future, it would be greater?
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.