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. Pagination of a QTextDocument

Pagination of a QTextDocument

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 2.4k 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.
  • A Offline
    A Offline
    akinakinyilmaz
    wrote on last edited by
    #1

    Hello I have a QTextDocument which is printed as a multiple page document when I print it to a pdf file :

    @QPrinter printer(QPrinter::HighResolution);
    printer.setOutputFormat(QPrinter::PdfFormat);
    printer.setOutputFileName(fileName);
    printer.setPaperSize(QPrinter::A4);
    doc->print(&printer);@

    doc is my QTextDocument and when I want to display it in a QTextEdit it shows it in a continuous fashion, not in seperate pages.
    @
    QTextEdit* displayArea = new QTextEdit;
    displayArea->setDocument(document);@

    What should I do, if I want my QTextDocument to be shown in different QTextEdits per page or are there any method for displaying each page of my QTextDocument seperately like in printed pdf?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      akinakinyilmaz
      wrote on last edited by
      #2

      Actually, it can be done with 2 ways :

      1. We can seperate documents by hand and then can give each page to one qtextedit for displaying, when printing we can print with painter :
        @ QPainter painter;
        painter.begin(&printer);
        docs[0]->drawContents(&painter);
        printer.newPage();
        docs[1]->drawContents(&painter);
        painter.end();@

      here doc[0] is document of first text edit.
      2. We can take all document and we can have a paginated view with QPrintPreviewDialog :
      printPreview will open the dialog :
      @void OurWidget::printPreview()
      {
      QPrinter printer(QPrinter::ScreenResolution);
      QPrintPreviewDialog preview(&printer, this);
      preview.setMinimumSize(1000,800);
      connect(&preview, SIGNAL(paintRequested(QPrinter*)), SLOT(preview(QPrinter*)));
      preview.exec();
      }@
      and preview is paint function of print preview widget :
      @void OurWidget::preview(QPrinter *printer)
      {
      doc->print(printer);
      }@

      here doc is a full document.

      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