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
Printable View
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
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()
Guess you are using point value to set the font:Quote:
Also the font is printed in different sizes.
Quote:
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.
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).
Yes, it's A4-paper. I also set the page margins manually.
How is the width of the page calculated?
Code:
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??
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
Can you give an example for that?
Sorry, missed your request... it's something like:
or you could just play with the painter window:Code:
// Set world coordinates to millimetres. QTransform t = QTransform::fromScale ( painter->device()->physicalDpiX() / 25.4, painter->device()->physicalDpiY() / 25.4 ); painter->setWorldTransform(t, false);
You need to be careful because the transforms will scale everything. You can also use the QTransform without changing the painter.Code:
// For portrait A4 paper in millimetres painter->setWindow(0, 0, 210, 297);