Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTextDocument page break
Qt 6.11 is out! See what's new in the release blog

QTextDocument page break

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 2.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    HB76
    wrote on last edited by
    #1

    Hi everyone,

    I am trying to generate pdf files thanks to QTextDocument and QPrinter. The problem is that the QTextDocument API doesn't provide solution to make page break. I was thinking about something like this but it doesn't work :

    void newPage(QTextDocument *document, QTextCursor *cursor)
    {
        int count = document->pageCount(); 
        while (document->pageCount()==count)
            cursor->insertHtml("<br>");
    }
    

    The problem is the pageCount remains always the same, I tried with the line count but it also remains constant even after adding html line breaks.

    So for now, I add html line breaks manually until the document create a new page, but it is a very poor solution as it is absolutely not flexible.
    I would like to keep it as simple as possible, this is why I didn't chose to use an external lib as KDReport.

    Do you have any idea ?

    Thanks !

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bonnie
      wrote on last edited by Bonnie
      #2

      Maybe you can refer to

      void QTextBlockFormat::setPageBreakPolicy(QTextFormat::PageBreakFlags policy)
      

      and

      void QTextFrameFormat::setPageBreakPolicy(QTextFormat::PageBreakFlags policy)
      

      They should also be able to be set in CSS

      page-break-before [ auto | always ] Make it possible to enforce a page break before the paragraph/table
      page-break-after [ auto | always ] Make it possible to enforce a page break after the paragraph/table

      1 Reply Last reply
      3
      • H Offline
        H Offline
        HB76
        wrote on last edited by
        #3

        Thanks it works ! Page break is automatically added after each block !

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved