Ankitha Varsha
20th June 2008, 14:06
Hi,
I am trying to divert the paint operations of a widget to the printer.
But it doesn't seem to work for me.
following is the code.
void print()
{
QPrinter printer;
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName("C:/sample.pdf");
printer.setPageSize(QPrinter::A4);
QPainter::setRedirected(widget, &printer);
QPaintEvent pe(this->rect());
qApp->sendEvent(this, &pe);
QPainter::restoreRedirected(widget);
widget->repaint();
}
Initially, i used widget->repaint() instead of sendevent(). But didnt work either.
If i query redirected() function on the widget before restoring the redirection , it is correctly showing the redirected device as printer. I wonder still why this code doesn't work!
Am i doing any mistake here?
Pls help
-
Ankitha
I am trying to divert the paint operations of a widget to the printer.
But it doesn't seem to work for me.
following is the code.
void print()
{
QPrinter printer;
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName("C:/sample.pdf");
printer.setPageSize(QPrinter::A4);
QPainter::setRedirected(widget, &printer);
QPaintEvent pe(this->rect());
qApp->sendEvent(this, &pe);
QPainter::restoreRedirected(widget);
widget->repaint();
}
Initially, i used widget->repaint() instead of sendevent(). But didnt work either.
If i query redirected() function on the widget before restoring the redirection , it is correctly showing the redirected device as printer. I wonder still why this code doesn't work!
Am i doing any mistake here?
Pls help
-
Ankitha