Results 1 to 5 of 5

Thread: QPrinter without page number

  1. #1
    Join Date
    Jan 2008
    Location
    Brasil
    Posts
    131
    Thanks
    18
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QPrinter without page number

    Good Day,

    I'm perfectly printing the contents of a QTextEdit using QPrinter, but do not want to appear the page number. Has how?

    Thanks,

    Marcelo Geyer
    Brazil

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPrinter without page number

    You can probably use QTextDocument::documentLayout() and QAbstractTextDocumentLayout::draw() to print each page yourself.

  3. #3
    Join Date
    Apr 2009
    Location
    Gdansk, Poland
    Posts
    11
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPrinter without page number

    Quote Originally Posted by wysota View Post
    You can probably use QTextDocument::documentLayout() and QAbstractTextDocumentLayout::draw() to print each page yourself.
    Is there any example how to do this? I cannot find anything in the network

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPrinter without page number

    I'm not sure what example you would want. You have to pass a QPainter initialized on the printer object to the method and an empty (default) paint context object and you're done.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Oct 2015
    Posts
    3
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QPrinter without page number

    This has been answered elsewhere, but for those who arrive here seeking the solution, I'm reposting it: you need to set a pageSize in the document, like so:

    Qt Code:
    1. QPrinter printer(QPrinter::PrinterResolution);
    2. printer.setPaperSize(QPrinter::A4);
    3. printer.setOutputFormat(QPrinter::PdfFormat);
    4. printer.setOutputFileName(fileName);
    5.  
    6. QTextDocument document;
    7. document.setHtml("<p>Lorem ipsum</p>");
    8. document.setPageSize(printer.pageRect().size()); // <-- Here is key to the solution
    9. document.print(&printer);
    To copy to clipboard, switch view to plain text mode 

    The explanation is simple, albeit not entirely intuitive. Paraphrasing @shoyeb from that thread:

    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 only will be printed if pageNumberPos is not null.
    So just set a valid QTextDocumtent.pageSize() and you'll have no page numbers on your printed document.

Similar Threads

  1. Displaying Page Number on a widget
    By LiCodeX in forum Newbie
    Replies: 1
    Last Post: 23rd August 2007, 09:34
  2. Line Number - QTextEdit...???
    By deepusrp in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2007, 17:34
  3. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 07:13
  4. How can I put text on each page using QPrinter
    By davit in forum Qt Programming
    Replies: 2
    Last Post: 15th April 2007, 13:23
  5. QWidget display on 2 stack widget page
    By spawnwj in forum Qt Programming
    Replies: 3
    Last Post: 4th September 2006, 13:07

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.