Results 1 to 8 of 8

Thread: How do I set a custom page/paper size in QPrinter

  1. #1
    Join Date
    Jul 2010
    Posts
    2
    Qt products
    Qt4

    Default How do I set a custom page/paper size in QPrinter

    hi

    How do I set a custom page/paper size in QPrinter?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How do I set a custom page/paper size in QPrinter


  3. #3
    Join Date
    Apr 2013
    Posts
    8
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How do I set a custom page/paper size in QPrinter

    Sorry for bringing this up, but I'm using QT 4.8 and it doesn't let me use that function, even though it's still present in the documentation.

    ¿Any clues? I've set my pagesize to A7, but it's a little large, and I would like to be able to customize it, in case I have to change it...

    EDIT: I've just set my default printer to adobe pdf to see the output and it completely ignored the size settings I made.
    Last edited by LautaroMed; 25th July 2013 at 05:47.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How do I set a custom page/paper size in QPrinter

    What does "it doesn't let me use that function" mean, especially give that your next sentence says you could set the page size?

    This, for example, compiles and runs fine under Qt 4.8.4:
    Qt Code:
    1. #include <QApplication>
    2. #include <QPrinter>
    3. #include <QPainter>
    4.  
    5. int main(int argc, char **argv)
    6. {
    7. QApplication app(argc, argv);
    8.  
    9. QPrinter printer;
    10. printer.setOutputFormat(QPrinter::PdfFormat);
    11. printer.setOutputFileName("test.pdf");
    12. printer.setPaperSize(QSizeF(2, 2), QPrinter::Inch);
    13.  
    14. QPainter p(&printer);
    15. p.drawLine(QPointF(0, 0), QPointF(72, 72));
    16. p.end();
    17.  
    18. return 0;
    19. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. $ pdfinfo test.pdf
    2. Title:
    3. Creator:
    4. Producer: Qt 4.8.4 (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
    5. CreationDate: Thu Jul 25 05:16:10 2013
    6. Tagged: no
    7. Form: none
    8. Pages: 1
    9. Encrypted: no
    10. Page size: 144 x 144 pts
    11. Page rot: 0
    12. File size: 1358 bytes
    13. Optimized: no
    14. PDF version: 1.4
    To copy to clipboard, switch view to plain text mode 
    Last edited by ChrisW67; 25th July 2013 at 06:18.

  5. #5
    Join Date
    Apr 2013
    Posts
    8
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How do I set a custom page/paper size in QPrinter

    I was using setPageSize I think.

    Anyway, I tried your code, and in my pc it generates an A4 size PDF:

    Qt Code:
    1. [QTCLASS]Title:
    2. Creator:
    3. Producer: Qt 4.8.1 (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
    4. CreationDate: 07/25/13 05:36:18
    5. Tagged: no
    6. Form: none
    7. Pages: 1
    8. Encrypted: no
    9. Page size: 212 x 284 pts
    10. File size: 1348 bytes
    11. Optimized: no
    12. PDF version: 1.4[/QTCLASS]
    To copy to clipboard, switch view to plain text mode 

    Here's the code I was using earlier:

    Qt Code:
    1. [QTCLASS]
    2. QTextDocument document;
    3. document.setHtml(strStream);
    4.  
    5. QPrinter printer;
    6.  
    7. printer.setColorMode(QPrinter::GrayScale);
    8. printer.setPaperSize(QPrinter::A7);
    9. qDebug() << printer.paperSize();
    10.  
    11. printer.setFullPage(false);
    12.  
    13. document.print(&printer);
    14. [/QTCLASS]
    To copy to clipboard, switch view to plain text mode 

    The qDebug line prints "30", whatever that means...

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How do I set a custom page/paper size in QPrinter

    QPrinter::Custom 30 Unknown, or a user defined size.
    You are setting a paper size of A7 which may not be valid for the default system printer. What does paperRect() return afterward?
    The PDF size you gave, 212 x 284 pts, is 74.8 x 100.2 mm... a shade wider and a few mm shorter than A7 portrait.

    QTextDocument maintains its own page size that may be passed to the printer.

    Have you tried the most recent Qt 4.8?

  7. #7
    Join Date
    Apr 2013
    Posts
    8
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How do I set a custom page/paper size in QPrinter

    paperRect() returns "QRect(0,0 283x378)"

    I am setting paper size like this now:

    Qt Code:
    1. printer.setPaperSize(QSizeF(75, 100), QPrinter::Millimeter);
    To copy to clipboard, switch view to plain text mode 

    I am using QT 4.8.1 because it's the only SDK I could find...

  8. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How do I set a custom page/paper size in QPrinter

    http://qt-project.org/downloads
    There's a Qt 4.8.4 bundle suitable for use with the old SDK's GCC 4.4, and the MingW builds of Qt 5.1 come with a MingW GCC 4.8 toolchain included.

Similar Threads

  1. QPrinter without page number
    By estanisgeyer in forum Qt Programming
    Replies: 4
    Last Post: 15th October 2015, 13:19
  2. QPrinter generates empty page
    By hayati in forum Qt Programming
    Replies: 3
    Last Post: 11th August 2009, 10:01
  3. Replies: 1
    Last Post: 7th July 2009, 16:46
  4. How I setup QPrinter paper margins
    By vcp in forum Qt Programming
    Replies: 3
    Last Post: 15th May 2008, 17:43
  5. How can I put text on each page using QPrinter
    By davit in forum Qt Programming
    Replies: 2
    Last Post: 15th April 2007, 12:23

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.