Hi,

With this sample code, I'm trying to do 7 frames with 8 lines of text each. When I print it in a PDF, the first line of the 7 frame is on the first page and the rest of the same frame is on the second page.

I would like that if the entire frame doesn't fit on the page, to have a page break before it to ensure the frame are never split.

I tough the "frameFormat.setPageBreakPolicy(QTextFormat::PageB reak_Auto);" would be enough.

Is there a way to do it? Or is it possible to know in advance if a frame will be split and do a "frameFormat.setPageBreakPolicy(QTextFormat::PageB reak_AlwaysBefore);" only for that frame?

thanks!

Qt Code:
  1. QTextDocument *doc = ui->textEdit->document();
  2.  
  3. QTextCursor cursor(doc);
  4.  
  5. for (int j=1; j<=7; j++) {
  6. QTextFrameFormat frameFormat;
  7. if (j % 2) {
  8. frameFormat.setBackground(Qt::red);
  9. }
  10. frameFormat.setPageBreakPolicy(QTextFormat::PageBreak_Auto);
  11.  
  12. cursor.movePosition(QTextCursor::NextBlock);
  13. cursor.insertFrame(frameFormat);
  14.  
  15. for (int i=1; i<=8; i++) {
  16. cursor.insertText(QString("frame %1 - line %2\n").arg(QString::number(j),
  17. QString::number(i)));
  18. }
  19. }
  20.  
  21. QPrinter *printer = new QPrinter();
  22. QPrintDialog printDialog(printer, this);
  23. if (printDialog.exec() == QDialog::Accepted) {
  24. doc->print(printer);
  25. }
To copy to clipboard, switch view to plain text mode