Results 1 to 8 of 8

Thread: Different paperSize of QPrinter on Windows and Mac

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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: 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

  2. #2
    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?

  3. #3
    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: 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
  •  
Qt is a trademark of The Qt Company.