Results 1 to 13 of 13

Thread: problem printing a multi page report

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #12
    Join Date
    Oct 2009
    Posts
    364
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    10
    Thanked 37 Times in 36 Posts

    Default Re: problem printing a multi page report

    Ok, got a little further. The printpreview now works, but it isn't behaving the way I want. Now that I have added the QTextEdit to the main window, the text gets formatted according to the widget's dimension. I guess that is kind of expected. What I really wanted is to create a nice looking multi page report and my reason for using QTextEdit is the Richly formatted text. What I didn't anticipate is the way the text is depending on the QTextEdit widget's dimension. Is there no way for me to create nicely formatted text but defer line wrapping etc. until it gets drawn onto the printer/painter device?
    Would I have to print to pdf in order to get what I want? I guess I could just try it, but I was wondering if I'm approaching this from the right direction.

    Here is my latest code.
    Qt Code:
    1. //Mainwindow constructor contains: printer = new QPrinter(QPrinter::ScreenResolution);
    2.  
    3. void MainWindow::print(QPrinter *printer)
    4. {
    5.  
    6. QPainter painter;
    7. painter.begin(printer);
    8.  
    9. ui->textEdit->append("first page this is a fairly long line to see what happens when it is being wrapped");
    10. ui->textEdit->document()->drawContents(&painter, printer->pageRect());
    11.  
    12. printer->newPage();
    13. ui->textEdit->clear();
    14. ui->textEdit->append("second page");
    15. ui->textEdit->document()->drawContents(&painter, printer->pageRect());
    16. ui->textEdit->clear();
    17.  
    18. painter.end();
    19. }
    20.  
    21. void MainWindow::on_pushButton_clicked()
    22. {
    23.  
    24. QPrintPreviewDialog preview(printer,this);
    25. connect(&preview, SIGNAL(paintRequested(QPrinter*)),SLOT(print(QPrinter *)));
    26. preview.exec();
    27.  
    28. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by schnitzel; 23rd January 2011 at 00:50.

Similar Threads

  1. multi page Application
    By ilpaso in forum Qt Programming
    Replies: 2
    Last Post: 3rd September 2010, 09:36
  2. Printing to a plain text (txt) file from a report
    By luizofoca in forum Qt Programming
    Replies: 0
    Last Post: 10th June 2010, 19:02
  3. Printing custom report with QWT
    By maluedo in forum Qwt
    Replies: 2
    Last Post: 6th April 2010, 11:09
  4. Replies: 1
    Last Post: 10th February 2009, 06:21
  5. Multi-Page PDF Output
    By igor in forum Qt Programming
    Replies: 1
    Last Post: 9th January 2007, 04:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.