I have a simple application with a database of book titles and authors.
I have created a query that I can print or preview displaying the result set.
My problem is that I want to change the default footer of the report to one that I can format, something like "01/31/1900 Page 1 of 13".

I would like to know several things:

1) what signal indicates a page break is about to occur.
2) and / or how do I format a footer for the breaking page.
3) since this is a document in a QTextEdit document is the formating done in the editor or in one or more of the document formats/frames?

This is my first jump into document printing with Qt. I am missing something but I am not clear as to what.

Qt Code:
  1. void MainWindow::getAllTitles(QPrinter *printer)
  2. {
  3. d->db = QSqlDatabase::database("booksconn",true);
  4. QDate date = QDate::currentDate();
  5. QString strDate = date.toString("d MMM yyyy");
  6.  
  7. printer->setPaperSize(QPrinter::Letter);
  8. // create a font appropriate to page size
  9. QFont bodyFont;
  10. QFont titleFont;
  11. titleFont.setStyleHint(QFont::Courier);
  12. titleFont.setPointSize(20);
  13. bodyFont.setStyleHint(QFont::Helvetica);
  14.  
  15. ui->editor->clear();
  16. QTextCursor acursor(ui->editor->textCursor());
  17. acursor.movePosition(QTextCursor::Start);
  18. QTextFrame *tpFrame = acursor.currentFrame();
  19.  
  20. QTextFrameFormat tFrameFormat;
  21. QTextFrameFormat bFrameFormat;
  22. bFrameFormat.setWidth(QTextLength(QTextLength::PercentageLength, 100));
  23.  
  24. QTextCharFormat textFormat;
  25. QTextCharFormat boldFormat;
  26. QTextCharFormat titleFormat;
  27. textFormat.setFont(bodyFont);
  28. titleFormat.setFont(titleFont);
  29. titleFormat.setFontWeight(QFont::Bold);
  30. boldFormat.setFontWeight(QFont::Bold);
  31. QTextFrame *tFrame = acursor.currentFrame();
  32. tFrame->setFrameFormat(tFrameFormat);
  33. acursor.insertFrame(tFrameFormat);
  34. acursor.setPosition(0);
  35. QString hdrtxt = "<h1 style=\"text-align: center; font-family: \'";
  36. hdrtxt += d->rtitleFont;
  37. hdrtxt += "\'; font-size: 20pt; font-weight: bold;\">";
  38. hdrtxt += "All Book Titles By Title";
  39. hdrtxt += "</h1><br>";
  40.  
  41. acursor.insertHtml(hdrtxt);
  42. QString dttxt = "<div style=\"text-align: center; font-family: \'";
  43. dttxt += d->rtitleFont;
  44. dttxt += "\' font-size: 11pt; font-weight: normal;\">";
  45. dttxt += strDate;
  46. dttxt += "</div>";
  47.  
  48. acursor.insertHtml(dttxt);
  49. acursor.setPosition(tFrame->lastPosition());
  50. acursor.endEditBlock();
  51. acursor.setPosition(tpFrame->lastPosition());
  52.  
  53. bFrameFormat.setWidth(QTextLength(QTextLength::PercentageLength, 100));
  54.  
  55. QTextFrame *topFrame = acursor.currentFrame();
  56. QTextFrameFormat topFrameFormat = topFrame->frameFormat();
  57. QTextFrameFormat titleFrameFormat;
  58. QTextFrameFormat bodyFrameFormat;
  59.  
  60. QTextFrame *titleFrame = acursor.currentFrame();
  61. topFrameFormat.setPadding(10);
  62. topFrame->setFrameFormat(topFrameFormat);
  63.  
  64. titleFrameFormat.setBorder(0);
  65. titleFrame->setFrameFormat(titleFrameFormat);
  66.  
  67.  
  68. QTextFrame *bodyFrame = acursor.currentFrame();
  69. bodyFrame->setFrameFormat(bodyFrameFormat);
  70.  
  71. QSqlQuery qry(d->db);
  72. QString strDML;
  73. strDML = "SELECT DISTINCT ";
  74. strDML += "Books.Title, Authors.LastName||', '||Authors.FirstName Author, ";
  75. strDML += "MediaType.Media ";
  76. strDML += "FROM ";
  77. strDML += " Books, Authors, MediaType ";
  78. strDML += "WHERE ";
  79. strDML += " Books.AuthKey = Authors.ID AND ";
  80. strDML += " Books.MediaKey = MediaType.ID ";
  81. strDML += "ORDER BY Books.Title, Author ";
  82.  
  83. qry.exec(strDML);
  84. qry.first();
  85. qry.last();
  86. qry.first();
  87.  
  88. QTextTableFormat tblFormat;
  89. tblFormat.setColumns(5);
  90. tblFormat.setCellPadding(1);
  91. tblFormat.setCellSpacing(2);
  92. tblFormat.setPageBreakPolicy(QTextFormat::PageBreak_Auto);
  93. tblFormat.setHeaderRowCount(1);
  94. acursor.insertBlock();
  95. acursor.beginEditBlock();
  96. QTextTable *tableBooks = acursor.insertTable(1,5,tblFormat);
  97. tableBooks->format().setPageBreakPolicy(QTextFormat::PageBreak_Auto);
  98. acursor = tableBooks->cellAt(0, 0).firstCursorPosition();
  99. QString coltxt;
  100. QApplication::setOverrideCursor(Qt::WaitCursor);
  101. QApplication::processEvents();
  102. acursor = tableBooks->cellAt(0,0).firstCursorPosition();
  103. coltxt = "<tr style=\"height: 15px; margin: 0; padding: 0;\">";
  104. coltxt += "<th style=\"";
  105. coltxt += "margin: 0; padding: 0; text-align: center; font-size: 14pt; font-family: '";
  106. coltxt += d->rsectionFont;
  107. coltxt += "'; border-bottom: 2px solid black;\">";
  108. coltxt += "<u>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
  109. coltxt += "Book Title&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</u></th>";
  110. acursor.insertHtml(coltxt);
  111. acursor = tableBooks->cellAt(0,1).firstCursorPosition();
  112. coltxt = "<th style=\"";
  113. coltxt += "margin: 0; padding: 0; text-align: center; font-size: 14pt; font-family: '";
  114. coltxt += d->rsectionFont;
  115. coltxt += "'; border-bottom: 2px solid black;\">&nbsp;</th>";
  116. acursor.insertHtml(coltxt);
  117. acursor = tableBooks->cellAt(0,2).firstCursorPosition();
  118. coltxt = "<th style=\"";
  119. coltxt += "margin: 0; padding: 0; text-align: center; font-size: 14pt; font-family: '";
  120. coltxt += d->rsectionFont;
  121. coltxt += "'; border-bottom: 2px solid black;\"><u>&nbsp;&nbsp;Author Name&nbsp;&nbsp;</u></th>";
  122. acursor.insertHtml(coltxt);
  123. acursor = tableBooks->cellAt(0,3).firstCursorPosition();
  124. coltxt = "<th style=\"";
  125. coltxt += "margin: 0; padding: 0; text-align: center; font-size: 14pt; font-family: '";
  126. coltxt += d->rsectionFont;
  127. coltxt += "'; border-bottom: 2px solid black;\"><u>&nbsp;&nbsp;Media&nbsp;&nbsp;</u></th></tr>";
  128. acursor.insertHtml(coltxt);
  129. int j = 1;
  130. do
  131. {
  132. if ( qry.record().field("Title").value().toString().trimmed() == "" ) break;
  133. tableBooks->insertRows(j,1);
  134. acursor = tableBooks->cellAt(j, 0).firstCursorPosition();
  135. acursor.insertText(qry.record().field("Title").value().toString().trimmed());
  136. acursor = tableBooks->cellAt(j,1).firstCursorPosition();
  137. acursor.insertText(" ");
  138. acursor = tableBooks->cellAt(j,2).firstCursorPosition();
  139. acursor.insertText(qry.record().field("Author").value().toString().trimmed());
  140. acursor = tableBooks->cellAt(j,3).firstCursorPosition();
  141. acursor.insertText(qry.record().field("Media").value().toString().trimmed());
  142. ++j;
  143.  
  144. } while ( qry.next() );
  145. qry.finish();
  146. acursor.setPosition(bodyFrame->lastPosition());
  147. acursor.endEditBlock();
  148. acursor.setPosition(topFrame->lastPosition());
  149. acursor.endEditBlock();
  150.  
  151. ui->editor->print(printer);
  152. }
To copy to clipboard, switch view to plain text mode 

Any help in this area would be a big asset.