Render canvas only to QImage
Hello,
I have a regular plot with a spectrogram (with title, axis ticks, etc...).
I need to render the plot canvas (without borders, axes, or anything else) to a QImage of a specific size (e.g. 512x512), for using it in QOpenGLTexture.
The goal is to map the spectrogram image directly to a rectangle in OpenGL, with no empty spaces.
I'm having trouble using QwtPlotRenderer for this task. The standard render() renders too much and there are empty spaces in canvas around the spectrogram as well. renderCanvas() requires a scale map which is rather confusing to me.
Is there some easier way I'm missing?
Thanks,
Alexander
Re: Render canvas only to QImage
Quote:
Originally Posted by
alex_sh
renderCanvas() requires a scale map which is rather confusing to me.
If the data of your spectrogram is in the range 100-2000 on the bottom axis and 10-20 on the left axis and you want to render to a 500x500 image:
Code:
maps
[QwtPlot::xBottom].
setPaintInterval( 0,
500 );
maps
[QwtPlot::xBottom].
setScaleInterval( 100,
200 );
maps
[QwtPlot::yLeft].
setPaintInterval( 0,
500 );
maps
[QwtPlot::yLeft].
setScaleInterval( 20,
10 );
Note that paint device coordinates are increasing from top to bottom, while y-scales usually have the smaller value at the bottom.
HTH,
Uwe
Re: Render canvas only to QImage
This works like a charm.
Thank you very much, Uwe!