Results 1 to 8 of 8

Thread: Different paperSize of QPrinter on Windows and Mac

  1. #1
    Join Date
    Oct 2008
    Location
    Germany
    Posts
    29
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Different paperSize of QPrinter on Windows and Mac

    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

  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: Different paperSize of QPrinter on Windows and Mac

    Quote Originally Posted by cevou View Post
    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.

  3. #3
    Join Date
    Oct 2008
    Location
    Germany
    Posts
    29
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Different paperSize of QPrinter on Windows and Mac

    I guess there is also a problem with the QPainter.

    For example...

    Qt Code:
    1. painter.drawText(QRectF(80.0, 20.0, 300.0, 17.0),QString(query2.value(1).toString())
    To copy to clipboard, switch view to plain text mode 

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

  4. #4
    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: Different paperSize of QPrinter on Windows and Mac

    Quote Originally Posted by cevou View Post
    ... 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).

  5. #5
    Join Date
    Oct 2008
    Location
    Germany
    Posts
    29
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Different paperSize of QPrinter on Windows and Mac

    Yes, it's A4-paper. I also set the page margins manually.

    Qt Code:
    1. printer.setPageMargins(5.0,5.0,5.0,5.0,QPrinter::Millimeter);
    To copy to clipboard, switch view to plain text mode 

    How is the width of the page calculated?

    Qt Code:
    1. printer.pageRect().width()
    To copy to clipboard, switch view to plain text mode 

    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??

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

    Default Re: Different paperSize of QPrinter on Windows and Mac

    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

  7. #7
    Join Date
    Oct 2008
    Location
    Germany
    Posts
    29
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Different paperSize of QPrinter on Windows and Mac

    Can you give an example for that?

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

    Default Re: Different paperSize of QPrinter on Windows and Mac

    Sorry, missed your request... it's something like:
    Qt Code:
    1. // Set world coordinates to millimetres.
    2. QTransform t = QTransform::fromScale (
    3. painter->device()->physicalDpiX() / 25.4,
    4. painter->device()->physicalDpiY() / 25.4 );
    5. painter->setWorldTransform(t, false);
    To copy to clipboard, switch view to plain text mode 
    or you could just play with the painter window:
    Qt Code:
    1. // For portrait A4 paper in millimetres
    2. painter->setWindow(0, 0, 210, 297);
    To copy to clipboard, switch view to plain text mode 
    You need to be careful because the transforms will scale everything. You can also use the QTransform without changing the painter.

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.