Results 1 to 3 of 3

Thread: [Help] Remove page number, on QTextDocument's print()

  1. #1
    Join Date
    Dec 2010
    Posts
    20
    Thanks
    9
    Thanked 3 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default [Help] Remove page number, on QTextDocument's print()

    Hi everyone

    Wonder if there is a way to remove page number on QTextDocument's print(QPrinter*)

  2. #2
    Join Date
    Dec 2010
    Posts
    20
    Thanks
    9
    Thanked 3 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: [Help] Remove page number, on QTextDocument's print()

    Finally I get my solution,

    Instead of QTextDocument's print(), I use QTextDocument's drawContents().

    Codes below will show the way how to do this:

    Qt Code:
    1. QTextDocument textDocument;
    2. printer->setPageMargins(0.925, 0.8, 0.5, 0.8, QPrinter::Inch); //set page margin
    3.  
    4. QSizeF paperSize;
    5. paperSize.setWidth(printer->width());
    6. paperSize.setHeight(printer->height());
    7. textDocument.setPageSize(paperSize);
    8.  
    9. QPainter painter(printer);
    10. textDocument.setHtml(contentFormula); //contentFormula contains some html tags
    11.  
    12. textDocument.drawContents(&painter);
    To copy to clipboard, switch view to plain text mode 

    hope this'll be usefull

  3. #3
    Join Date
    Oct 2011
    Posts
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: [Help] Remove page number, on QTextDocument's print()

    Hello,

    you can also use the print() method to print without the page number!
    The key is, that the QTextDocument needs a valid pageSize.

    Qt Code:
    1. QPrinter printer(QPrinter::ScreenResolution);
    2. printer.setPaperSize(QPrinter::A4);
    3. printer.setOutputFormat(QPrinter::PdfFormat);
    4. printer.setOutputFileName( fileName );
    5. // printer.setPageMargins(0.925, 0.8, 0.5, 0.8, QPrinter::Inch);
    6.  
    7. QSizeF paperSize;
    8. paperSize.setWidth(printer.width());
    9. paperSize.setHeight(printer.height());
    10. document->setHtml(html);
    11. document->setPageSize(paperSize); // the document needs a valid PageSize
    12. document->print(&printer);
    To copy to clipboard, switch view to plain text mode 

    When you refer the source code of print(), then you will recognize that the < QPointF pageNumberPos; > is only defined when there is no valid QTextDocument.pageSize().
    In printPage() the page number will be just printed, if pageNumberPos is not null.
    So just set a valid QTextDocumtent.pageSize() and you have no page numbers on your printed document.

    I hope this bug will be fixed in a future release. (It's a reported bug)

    good luck

Similar Threads

  1. QTextDocument: print or drawContents?
    By giusepped in forum Qt Programming
    Replies: 3
    Last Post: 9th November 2010, 08:20
  2. Print of QTextDocument
    By tsschulz in forum Qt Programming
    Replies: 1
    Last Post: 2nd November 2008, 10:18
  3. QTextDocument line number
    By bunjee in forum Qt Programming
    Replies: 14
    Last Post: 10th June 2008, 13:49
  4. QTabWidget remove a page at the page's request
    By thomaspu in forum Qt Programming
    Replies: 2
    Last Post: 29th December 2007, 20:45
  5. Replies: 0
    Last Post: 28th June 2006, 20:49

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.