PDA

View Full Version : Different paperSize of QPrinter on Windows and Mac



cevou
11th June 2009, 16:47
Hi,

why does printer.paperRect().width() return different values on Windows and Mac?
I created all my reports on a Windows PC. Now I want to print exactly the same on an OSX system.
Also the font is printed in different sizes.

Chris

Lykurg
11th June 2009, 16:56
why does printer.paperRect().width() return different values on Windows and Mac?

Specify your paper size! If not the default values of your system are used and there obviously your win ond osx have different settings. Look: QPrinter::paperSize()


Also the font is printed in different sizes.
Guess you are using point value to set the font:

Note: When rendering text on a QPrinter device, it is important to realize that the size of text, when specified in points, is independent of the resolution specified for the device itself. Therefore, it may be useful to specify the font size in pixels when combining text with graphics to ensure that their relative sizes are what you expect.

cevou
11th June 2009, 18:30
I guess there is also a problem with the QPainter.

For example...


painter.drawText(QRectF(80.0, 20.0, 300.0, 17.0),QString(query2.value(1).toString())

... prints the text more on the right hand side in OSX then in Windows.
Is this also a Problem with points/pixels?

Lykurg
11th June 2009, 18:46
... prints the text more on the right hand side in OSX then in Windows.
Is this also a Problem with points/pixels?

Depends. How have you measured that? Is on both systems - I guess - A4 paper size set to the QPrinter? Some printer driver adds an extra border while printing, but that is a local setting of your printer/"driver-user-settings", you can't influence (at least not simply).

cevou
11th June 2009, 19:01
Yes, it's A4-paper. I also set the page margins manually.


printer.setPageMargins(5.0,5.0,5.0,5.0,QPrinter::M illimeter);

How is the width of the page calculated?


printer.pageRect().width()

returns (on both systems configured as A4) different values. (Windows 796, Mac OSX 516)

Is it possible that it has something to do with the resolution??

ChrisW67
12th June 2009, 02:40
I guess that if you look at the painter.device().logicalDpiX() and physicalDpiX() (or the Y equivalents) on the two platforms you'll find they are different. They possibly even change from printer to printer on the same platform. By default there's a 1:1 mapping from logical to physical.

If you are relying on the same numbers giving the same physical location on a page regardless of the underlying paint device then you'll need to look at setting a transformation to ensure that your logical coordinate system is what you expect. I have tended to set a transform to allow positioning in millimetres, but you might choose points, inches, light-seconds etc :)

Of course, I could be talking rubbish...I'm new to Qt

cevou
12th June 2009, 09:10
Can you give an example for that?

ChrisW67
15th June 2009, 08:55
Sorry, missed your request... it's something like:


// Set world coordinates to millimetres.
QTransform t = QTransform::fromScale (
painter->device()->physicalDpiX() / 25.4,
painter->device()->physicalDpiY() / 25.4 );
painter->setWorldTransform(t, false);
or you could just play with the painter window:


// For portrait A4 paper in millimetres
painter->setWindow(0, 0, 210, 297);

You need to be careful because the transforms will scale everything. You can also use the QTransform without changing the painter.