Greetings everyone!
I'm having a trouble with printing via Qt.
What I want - is to print the viewable content of MainWindow using QPrint. I have printed test sheets using this code:
Qt Code:
  1. void MainWindow::setup_print(void)
  2. {
  3. dialog = new QPrintDialog(&printer, this);
  4. if (dialog->exec() == QDialog::Accepted)
  5. {
  6. QPainter painter( &printer );
  7.  
  8. painter.setPen( Qt::black );
  9.  
  10. for( int page=0; page<5; page++ )
  11. {
  12. painter.drawRect( printer.pageRect() );
  13. painter.drawLine( printer.pageRect().topLeft(), printer.pageRect().bottomRight() );
  14. painter.drawLine( printer.pageRect().topRight(), printer.pageRect().bottomLeft() );
  15. painter.drawRect(this->contentsRect() );
  16. QRectF textArea(
  17. printer.pageRect().left() +printer.resolution() * 0.5,
  18. printer.pageRect().top() +printer.resolution() * 0.5,
  19. printer.pageRect().width() -printer.resolution() * 1.0,
  20. printer.pageRect().height()-printer.resolution() * 1.5 );
  21.  
  22. painter.drawRect( textArea );
  23.  
  24. painter.drawText( textArea, Qt::AlignTop | Qt::AlignLeft, QString( "Page %1" ).arg( page+1 ) );
  25.  
  26. if( page != 4 )
  27.  
  28. printer.newPage();
  29. }
  30. }
  31. }
To copy to clipboard, switch view to plain text mode 
the "printer" object is mainwindow class member.
The problem is that I have no idea how to get the content of mainwindow be represented as a QPainter object.
Can anyone help me with this please?