Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Pagination of a QTextDocument

    General and Desktop
    1
    2
    2002
    Loading More Posts
    • 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
      akinakinyilmaz last edited by

      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 Reply Quote 0
      • A
        akinakinyilmaz last edited by

        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 Reply Quote 0
        • First post
          Last post