gkarthick5
1st June 2011, 14:52
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
void HistogramPlot::writeToPrinter(QPrinter* printer)
{
QwtPlotRenderer rend;
QPainter painter(printer);
rend.setDiscardFlag(QwtPlotRenderer::DiscardNone, true);
rend.setDiscardFlag(QwtPlotRenderer::DiscardBackgr ound, true);
QwtScaleMap *maps = new QwtScaleMap[this->axisCnt];
QwtScaleTransformation* xx = new QwtScaleTransformation(QwtScaleTransformation::Lin ear);
for(int axis = 0; axis< this->axisCnt; axis++)
maps[axis].setTransformation(xx);
rend.render(this, &painter, printer->pageRect());
painter.end();
}
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);
I use Qt 4.7.1 and Qwt 6.0.0
class HistogramPlot: public QwtPlot
void HistogramPlot::writeToPrinter(QPrinter* printer)
{
QwtPlotRenderer rend;
QPainter painter(printer);
rend.setDiscardFlag(QwtPlotRenderer::DiscardNone, true);
rend.setDiscardFlag(QwtPlotRenderer::DiscardBackgr ound, true);
QwtScaleMap *maps = new QwtScaleMap[this->axisCnt];
QwtScaleTransformation* xx = new QwtScaleTransformation(QwtScaleTransformation::Lin ear);
for(int axis = 0; axis< this->axisCnt; axis++)
maps[axis].setTransformation(xx);
rend.render(this, &painter, printer->pageRect());
painter.end();
}
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);
I use Qt 4.7.1 and Qwt 6.0.0