Results 1 to 7 of 7

Thread: QPrinter does not match documentation

  1. #1
    Join Date
    Oct 2011
    Posts
    7
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Question QPrinter does not match documentation

    Hello,
    I am trying to print out some pictures and documents in my program.
    I read the documentation "Printing with Qt". In the doc , it says:
    "The rectangle returned by pageRect() usually lies inside the rectangle returned by paperRect(). You do not need to take the positions and sizes of these area into account when using a QPainter with a QPrinter as the underlying paint device; the origin of the painter's coordinate system will coincide with the top-left corner of the page rectangle, and painting operations will be clipped to the bounds of the drawable part of the page."
    However, when I am doing print jobs, I find that the actual origin is the top-left of paper rectangle.
    I construct QPrinter object by passing QPrinterInfo to the constructor.
    Then , I construct the QPainter by passing QPrinter object to the QPainter's constructor.

    Does anybody have ideas on this issue?

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPrinter does not match documentation

    Quote Originally Posted by hugh_lou View Post
    Hello,
    the origin of the painter's coordinate system will coincide with the top-left corner of the page rectangle,
    However, when I am doing print jobs, I find that the actual origin is the top-left of paper rectangle.
    may be i did not got your question, but you stated exactly what is written in docs.

  3. #3
    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 does not match documentation

    I think he meant page vs paper. However without knowing how is the paper rect related to page rect in case of OP's settings, it is impossible to state whether the behaviour is correct or not.
    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.


  4. #4
    Join Date
    Oct 2011
    Posts
    7
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QPrinter does not match documentation

    Quote Originally Posted by nish View Post
    may be i did not got your question, but you stated exactly what is written in docs.
    Thanks for your reply. Just let me make the question clearer.
    The following pseudo code is a snippet of my code:
    Qt Code:
    1. QPrinter printer(printerInfo , QPrinter::HighResolution);
    2. printer.setPageMargins( 10.0 , 10.0 , 10.0 , 10.0 , QPrinter::DevicePixel );
    3. QRect totalRect = printer.pageRect();
    4. QPainter painter( &printer );
    5. //Here, I draw the text from (0,0)
    6. painter.drawText( QRect(0,0,totalRect.width() , totalRect.height() ) ,
    7. Qt::AlignLeft | Qt::TextJustificationForced | Qt::TextIncludeTrailingSpaces
    8. | Qt::TextExpandTabs | Qt::TextWordWrap
    9. | Qt::TextWrapAnywhere ,
    10. text );
    To copy to clipboard, switch view to plain text mode 
    According to the doc , if I want to draw text from the top-left corner of page rectangle, I do not need to consider the paper rectangle
    because "the origin of the painter's coordinate system will coincide with the top-left corner of the page rectangle".
    Therefore, I draw text from the coordinates ( 0 , 0 ). However , when I test this with a printer, I find that the text is printed out of
    both left and right edge.
    Then I tried to adjust the rect for drawing text, when I shrink the text rect for , say 10 pixels, it will work well.
    I think this implies that the origin of painter is not the top-left corner of page rectangle or I make mistakes in the code.

  5. #5
    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: QPrinter does not match documentation

    10 "pixels" at 300, 600, or 1200 dots per inch (i.e. typical printer resolution) is less than a millimetre from the page edges: your pageRect() and paperRect() are very similar. That position is probably comparable to the tolerance of paper positioning in the printer, and less than the typical non-printable margin on a printer.

  6. #6
    Join Date
    Oct 2011
    Posts
    7
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Smile Re: QPrinter does not match documentation

    Quote Originally Posted by ChrisW67 View Post
    10 "pixels" at 300, 600, or 1200 dots per inch (i.e. typical printer resolution) is less than a millimetre from the page edges: your pageRect() and paperRect() are very similar. That position is probably comparable to the tolerance of paper positioning in the printer, and less than the typical non-printable margin on a printer.
    You are right. I just misunderstood the conception "page margin".
    The QPrinter::setPageMargin function gave me a illusion that the entire paper is drawable.

    Thanks for your reply.

  7. #7
    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: QPrinter does not match documentation

    All printing occurs inside the page rect, which is offset from the paper edges by the margins you set. The entire paper area is addressable if you set pageRect == paperRect by setting the margins to zero or setFullPage(true). Your margins, while not zero, were so small that the page rect would barely be visibly different from the paper rect.

    What is actually printed is constrained by the printer's non-printable areas, typically a couple of millimetres all around but variable by printer: this is not considered by Qt at all.

    There's also a bug regarding setFullPage() on Windows: QTBUG-5363

Similar Threads

  1. no match for 'operator=' in...
    By toss in forum Newbie
    Replies: 2
    Last Post: 14th April 2010, 00:08
  2. Replies: 1
    Last Post: 21st September 2009, 07:30
  3. No match for operator>>
    By Salazaar in forum Newbie
    Replies: 18
    Last Post: 12th June 2007, 17:48
  4. Adding Qt's documentation to Xcode documentation browser
    By fabietto in forum Qt Programming
    Replies: 0
    Last Post: 10th June 2007, 15:38
  5. QPrinter::PrinterMode and QPrinter::setResolution??
    By SkripT in forum Qt Programming
    Replies: 2
    Last Post: 28th April 2006, 11:59

Tags for this Thread

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.