Re: Save QwtPlot as an image
In case anyone is interested, this is what I did:
QImage img(512, 512, QImage::Format_ARGB32);
QwtPlotPrintFilter pf;
pf.setOptions(QwtPlotPrintFilter::PrintAll);
bool use_painter = false;
if (use_painter) {
QPainter painter;
painter.begin(&img);
qpFACS->print(&painter,QRect(0, 0, 512, 512),pf);
painter.end();
} else {
qpFACS->print(img,pf);
}
img.save(path);
where qpFACS is a QwtPlot. Both methods work, producing the bare plot. I haven't found how to get the frame, axes, titles etc. If somebody can tell me what I need to do I'll be grateful.
Gib
Re: Save QwtPlot as an image
IIRC all elements should be part of what is generated by QwtPlot::print out of the box.
But a migration from Qwt 5 to 6 is not that hard and before fiddling around with versions that are ~10 years old ...
Uwe
Re: Save QwtPlot as an image
I can't recall now why I was reluctant to migrate to Qwt 6, but I think that something I was doing was not going to work the same way, and since 5 was doing everything I needed I decided not to rock the boat.
Added after 55 minutes:
I've been experimenting with the Bode example, saving the plot to an image file with
d_plot->print(img,pf)
Interestingly, in the image the only things that appear outside of the actual plot area are the short yellow and cyan lines that appear next to 'Amplitude and 'Phase' at the bottom. Since the image background is black, I surmise that nothing else shows because all the rest (axis title, title, axis markings etc) are black. Apparently I need to change the background of the printed image to white (it is grey onscreen). I thought that this might do it:
pf.color(Qt::GlobalColor::white,QwtPlotPrintFilter ::WidgetBackground);
but it has no effect, and nor does the same with CanvasBackground, and nor does trying to change AxisTitle by the method.
Maybe I am misunderstanding what pf.color() is supposed to do.