I use PlotRescaler to get my axis displayed proportionally, regardless of the plot size (currently I'm using the X-Axis as reference):
PlotRescaler
::PlotRescaler(QwtPlot * chart
) : QwtPlotRescaler(chart->canvas())
{
setRescalePolicy(QwtPlotRescaler::Fitting);
setAspectRatio(0.0);
setAspectRatio
(QwtPlot::yLeft,
1.0);
}
PlotRescaler::PlotRescaler(QwtPlot * chart) :
QwtPlotRescaler(chart->canvas())
{
setRescalePolicy(QwtPlotRescaler::Fitting);
setAspectRatio(0.0);
setAspectRatio(QwtPlot::yLeft, 1.0);
}
To copy to clipboard, switch view to plain text mode
When I resize my chart widget, the y-axis limits get updated accordingly to keep the aspect ratio.
However, when I render my chart to bitmap/vector via QwtPlotRenderer, for example with:
QPdfWriter pdfWriter( fname );
pdfWriter.setPageSizeMM( sizeMM );
pdfWriter.setTitle( title );
pdfWriter.setPageMargins( QMarginsF() );
pdfWriter.setResolution( resolution );
renderer.render( m_chart, &painter, documentRect );
QPdfWriter pdfWriter( fname );
pdfWriter.setPageSizeMM( sizeMM );
pdfWriter.setTitle( title );
pdfWriter.setPageMargins( QMarginsF() );
pdfWriter.setResolution( resolution );
QPainter painter( &pdfWriter );
renderer.render( m_chart, &painter, documentRect );
To copy to clipboard, switch view to plain text mode
hereby using arbitrary target sizes that differ from the current screen ratio, the aspect ratio is not maintained. Apparently, the rescaler is not notified of the chart/plot layout dimension change during the rendering.
Is there a workaround/easy fix for that or do I have to modify QwtPlotRenderer to manually apply the rescaling after the plot layout update?
Thanks,
Andreas
Bookmarks