Embedding Qwt plot High Resolution
I have the following problem.
If I print a plot, for example its pdf version, the resolution is high and acceptable.
Now, I would like to embed the plot in a TextDocument and print the document with the plots rendered as in the pdf file.
I tried to grab the widget containing the plot, inserting the image inside the document and thenprint out. But, as I expected, the quality of the plot is very low.
There is a way to solve this problem?
G
Re: Embedding Qwt plot High Resolution
Use QwtPlot::print - it renders to any kind of paint device. I recommend to use a QSvgGenerator (= vector graphics ) but you can also render to a QImage and save it in the format you like.
When you render to a QImage don't forget:
QImage image(...);
image.fill(Qt::transparent); // or whatever background you want to have
...
HTH,
Uwe
Re: Embedding Qwt plot High Resolution
Uwe,
I would like to use SVG but as I stated in another post, SVG does not handle very well the borders of my plots...
1 Attachment(s)
Re: Embedding Qwt plot High Resolution
Anyway, the way suggested by UWE produces a plot without axis.
I used the following code:
Code:
...
....
{
QSvgGenerator generator;
filter.setOptions(options);
image->fill(Qt::white);
return image;
}
As you can see, the image is in poor quality too.
Re: Embedding Qwt plot High Resolution
a) Qwt 5.2 clips the curves at the canvas borders for SVG.
b) The posted code snippet is nonsense - but if it has something to do with the application you are using for rendering your image: 400x600 is a very low resolution.
If you want an high resolution image you need to create a much larger QImage ( the size of the image is the resolution !). But it's obvious that using Qwt 5.2 with SVG ( or PDF - what is also a vector graphics format ) is much better than using any raster graphics format that produces huge output.
Uwe
Re: Embedding Qwt plot High Resolution
I found a solution and it works good.
Code:
...
int pw = printer.pageRect().width();
int ph =printer.pageRect().height();
p.begin(&printer);
p.save();
m_document->adjustSize();
QTransform tra;
tra.scale(11,11);
p.setTransform(tra);
m_document->drawContents(&p,printer.paperRect());
p.restore();
QRect rec
(-10,
0,pw
-10,
0.4*ph
);
p.translate(0,0.65*ph);
solarDiagram->print(&p,rec,filter);
p.end();
This is good for A4 paper. The plot is rendered as a vector graphic and I like it.
But I would scale the painter automatically. The value "11" is taken from a trial-and-correct approach.
Moreover, I noticed that if I translate the painter, Qwtplot does not print the title of the plot anymore. If I do not translate the painter everything is printerd.Why?
Re: Embedding Qwt plot High Resolution
Probably a bug in Qwt, that doesn't handle the translation. Try to translate the target rectangle instead of the painter.
Uwe
Re: Embedding Qwt plot High Resolution
How? May you a bit more detailed....
What do you mean for target rect?
G