I have a QwtPlot in which i add multiple Histograms (Histogram is the class from the "tvplot" example). When i try to print the plot to a QPrinter ( i tried with a pdf and jpeg file), i get the axes, labels, title and legend printed. But no data. What should i do to get the bars also printed?
class HistogramPlot
: public QwtPlot
class HistogramPlot: public QwtPlot
To copy to clipboard, switch view to plain text mode
void HistogramPlot
::writeToPrinter(QPrinter* printer
) {
QwtPlotRenderer rend;
rend.setDiscardFlag(QwtPlotRenderer::DiscardNone, true);
rend.setDiscardFlag(QwtPlotRenderer::DiscardBackground, true);
for(int axis = 0; axis< this->axisCnt; axis++)
maps[axis].setTransformation(xx);
rend.render(this, &painter, printer->pageRect());
painter.end();
}
void HistogramPlot::writeToPrinter(QPrinter* printer)
{
QwtPlotRenderer rend;
QPainter painter(printer);
rend.setDiscardFlag(QwtPlotRenderer::DiscardNone, true);
rend.setDiscardFlag(QwtPlotRenderer::DiscardBackground, true);
QwtScaleMap *maps = new QwtScaleMap[this->axisCnt];
QwtScaleTransformation* xx = new QwtScaleTransformation(QwtScaleTransformation::Linear);
for(int axis = 0; axis< this->axisCnt; axis++)
maps[axis].setTransformation(xx);
rend.render(this, &painter, printer->pageRect());
painter.end();
}
To copy to clipboard, switch view to plain text mode
HistogramPlot *qp = new HistogramPlot;
//...(Other Code Here)
printer.
setOrientation(QPrinter::Portrait);
printer.
setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName("temp.pdf");
qp->writeToPrinter(&printer);
HistogramPlot *qp = new HistogramPlot;
//...(Other Code Here)
QPrinter printer;
printer.setOrientation(QPrinter::Portrait);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName("temp.pdf");
printer.setPageSize(QPrinter::A4);
qp->writeToPrinter(&printer);
To copy to clipboard, switch view to plain text mode
I use Qt 4.7.1 and Qwt 6.0.0
Bookmarks