From Qt Documentation

void QPainter::setRedirected ( const QPaintDevice * device, QPaintDevice * replacement, const QPoint & offset = QPoint() ) [static]
Redirects all paint commands for the given paint device, to the replacement device. The optional point offset defines an offset within the source device.
The redirection will not be effective until the begin() function has been called; make sure to call end() for the given device's painter (if any) before redirecting. Call restoreRedirected() to restore the previous redirection.
In general, you'll probably find that calling QPixmap::grabWidget() or QPixmap::grabWindow() is an easier solution.
sendEvent "post" an event then the paintEvent method is invoked after you exit from print.

You can do this
Qt Code:
  1. void
  2. MyWidget::print()
  3. {
  4. QPrinter printer;
  5.  
  6. ....
  7.  
  8. QPixmap myPix = QPixmap::grabWidget(this);
  9.  
  10. QPainter painter;
  11. painter.begin(&printer);
  12.  
  13. painter->drawPixmap(0, 0, myPix);
  14.  
  15. painter.end();
  16. }
To copy to clipboard, switch view to plain text mode 

QPixmap::grabWidget calls QWidget::paintEvent()