Results 1 to 8 of 8

Thread: Printing with a coordinate system given in millimeters

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Printing with a coordinate system given in millimeters

    If you scale the canvas in milimeters, the font size will also have to be given in milimeters but scaled with a factor matching the one between the window and the viewport (in other words you have to calculate how many "pixels" or "points" fit into one "milimeter").
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  2. The following user says thank you to wysota for this useful post:

    doberkofler (25th April 2010)

  3. #2
    Join Date
    Apr 2010
    Posts
    18
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Printing with a coordinate system given in millimeters

    HI, I have a quite similar problem, I want to print a square 20 * 20 mm and I'm using this code:

    Qt Code:
    1. QPrinter printer;
    2. printer.setPaperSize(QPrinter::A4);
    3. printer.setOrientation (QPrinter::Portrait);
    4.  
    5. QPainter painter;
    6. int LogicalWidth = 210;
    7. int LogicalHeight = 297;
    8. painter.setWindow(0, 0,LogicalWidth, LogicalHeight);
    9. int PhysicalWidth = printer.width();
    10. int PhysicalHeight = printer.height();
    11. painter.setViewport(0, 0, PhysicalWidth, PhysicalHeight);
    12. painter.begin(&printer);
    13. painter.drawRect(50,50,20,20);
    14. painter.end();
    To copy to clipboard, switch view to plain text mode 

    the square I obtain is quite 5*5 mm , but i expect a square 20 * 20 mm...where is my mistake?
    Thankyou in advance.
    Last edited by wysota; 25th April 2010 at 19:42. Reason: missing [code] tags

  4. #3
    Join Date
    Oct 2009
    Location
    Vienna, Austria
    Posts
    57
    Thanks
    24
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Printing with a coordinate system given in millimeters

    This is strange as your example looks correct to me. Maybe "wysota" has an idea.

  5. #4
    Join Date
    Apr 2010
    Posts
    18
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Printing with a coordinate system given in millimeters

    Thanks for reply.
    I resolved my problem in this way: taking in account printer resolution (hoping this is a general solution) :

    QTransform TPiXEL = QTransform::fromScale(
    painter.device()->physicalDpiX() / 25.400,
    painter.device()->physicalDpiY() / 25.400);
    painter.setWorldTransform(TPiXEL, false);

    Thanks.
    Last edited by _Jack_; 30th April 2010 at 15:36. Reason: updated contents

  6. #5
    Join Date
    Oct 2009
    Location
    Vienna, Austria
    Posts
    57
    Thanks
    24
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Printing with a coordinate system given in millimeters

    Are you now using setWorldTransform together with setWindow/setViewport or instead of the method suggested by wysota?

Similar Threads

  1. coordinate system
    By Wojtek.wk in forum Newbie
    Replies: 7
    Last Post: 12th April 2010, 13:47
  2. 2D Graphics on coordinate system
    By soumya in forum Qt Programming
    Replies: 0
    Last Post: 4th November 2009, 06:27
  3. Replies: 1
    Last Post: 9th April 2009, 14:54
  4. The coordinate system
    By avis_phoenix in forum Qt Programming
    Replies: 1
    Last Post: 28th July 2008, 12:16
  5. Replies: 22
    Last Post: 7th December 2007, 09:01

Tags for this Thread

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.