I can't wrap my mind around printing multiple pages using QPrintPreviewDialog. I searched the forum and the web, nothing helpful came up.

My goal is to print invoices, each page consists of a letter head at the top, followed by the details for the particular customer.

I have no trouble doing this for a single page but I wanted to get a preview with N invoices, each on a separate page.

Here is what I do now:

Qt Code:
  1. void MainWindow::prepHeader(QTextEdit &t)
  2. {
  3.  
  4. t.append(QString("a nice letter head"));
  5. t.append("\n");
  6.  
  7. t.append(QString("customer info\n"));
  8.  
  9. t.append("\n\n\n\n\n\n______________________________________________________________\n"); //divider and some spacing
  10.  
  11. }
  12.  
  13.  
  14. void MainWindow::printReport(QTextEdit &pte, QString detail, bool bPreview)
  15. {
  16.  
  17. QPrintPreviewDialog pvw(printer,this);
  18.  
  19. if (bPreview)
  20. connect(&pvw, SIGNAL(paintRequested(QPrinter *)), SLOT(printPreview(QPrinter *)));
  21.  
  22. prepHeader(pte); //show a company specific letter head
  23.  
  24. pte.append(detail);
  25.  
  26.  
  27. if (bPreview)
  28. {
  29. pvw.exec();
  30. pvw.disconnect();
  31. pte.clear();
  32. }
  33. else
  34. pte.print(printer);
  35.  
  36. }
  37.  
  38. void MainWindow::printPreview(QPrinter *printer)
  39. {
  40. rpt.print(printer);
  41.  
  42. }
  43.  
  44. void MainWindow::printInvoice()
  45. {
  46. QString detail;
  47. QTextStream strm(&detail);
  48.  
  49.  
  50. strm << "customer details" << endl;
  51.  
  52. printReport(rpt, detail, true);
  53.  
  54. detail.clear();
  55. }
To copy to clipboard, switch view to plain text mode