PDA

View Full Version : QPrinter does not match documentation



hugh_lou
19th October 2011, 09:01
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?

nish
19th October 2011, 09:31
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.

wysota
19th October 2011, 11:21
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.

hugh_lou
20th October 2011, 04:13
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:


QPrinter printer(printerInfo , QPrinter::HighResolution);
printer.setPageMargins( 10.0 , 10.0 , 10.0 , 10.0 , QPrinter::DevicePixel );
QRect totalRect = printer.pageRect();
QPainter painter( &printer );
//Here, I draw the text from (0,0)
painter.drawText( QRect(0,0,totalRect.width() , totalRect.height() ) ,
Qt::AlignLeft | Qt::TextJustificationForced | Qt::TextIncludeTrailingSpaces
| Qt::TextExpandTabs | Qt::TextWordWrap
| Qt::TextWrapAnywhere ,
text );

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.

ChrisW67
20th October 2011, 10:55
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.

hugh_lou
21st October 2011, 03:47
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.

ChrisW67
21st October 2011, 04:16
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 (https://bugreports.qt.nokia.com/browse/QTBUG-5363)