PDA

View Full Version : printing with QwtPlot::print



user
7th March 2008, 05:03
I created a plot and I would like to print it.
From the Qwt examples, I used the bode example to create a print function:


void plotsMainWindow::print( ResultsPlot * plot )
{
QPrinter printer;
printer.setOrientation( QPrinter::Landscape );
QPrintDialog dialog( &printer );
if ( dialog.exec() )
{
QwtPlotPrintFilter filter;
if ( printer.colorMode() == QPrinter::GrayScale )
{
filter.setOptions ( QwtPlotPrintFilter::PrintAll & ~QwtPlotPrintFilter::PrintCanvasBackground );
}
plot->print( printer, filter );
}
}

When I try to print to a pdf document, the plot is printed but I have a light gray background.
I would like the plot on a white background, or no background at all.
When defining the canvas for the plot I used:

canvas_->setBackgroundRole( QPalette::Window );
canvas_->setAutoFillBackground( true );
the displayed plot on the screen shows a window background but it's different in the printing.

Also the documentation says that QwtPlotPrintFilter will be removed in future versions.
Should I use a different way to print the plot?

Uwe
7th March 2008, 07:56
Come on, did you ever try to understand the code you have copied ?
It disables the background for non colored prints. Simply remove the if condition if you want to disable the background for colored prints too.

In Qwt 6.x there will be no QwtPlotPrintFilter anymore. Filtering fonts and colors was possible in early Qwt releases, because there were only curves and markers. Today there are many other individual plot items, that are not known to QwtPlot.
But of course the flags controlling the plot won't be removed.

Uwe

PD: I fixed several print layout issues last week. It might be worth to download Qwt from the 5.0 SVN branch.