Results 1 to 3 of 3

Thread: Text too big while printing after using SetWindow()

  1. #1
    Join Date
    Feb 2008
    Location
    South Korea
    Posts
    14
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Text too big while printing after using SetWindow()

    Hi all,

    I want to print a form with lines/graphics and text, passing millimeters as coordinates to the painter functions.
    To achive this I use SetWindow() on the painter object.
    This works perfectly for the lines, but when I try to print some text, the font-size is way too big.
    I had a look at the font object properties while debugging, and the point-size was 10 points, but the pixel-size was 167!
    How can I make the font print at 10 points, while maintaining the millimeter coordinate system?

    Example code:
    Qt Code:
    1. printer = new QPrinter(QPrinter::PrinterResolution);
    2. ...
    3. //set pens and fonts
    4. QPen pen03;
    5. pen03.setWidthF(0.3);
    6.  
    7. QPen pen01;
    8. pen01.setWidthF(0.1);
    9.  
    10. QFont arial10("Arial", 10, QFont::Normal);
    11.  
    12. //draw the form
    13. QPainter painter;
    14. painter.begin(printer);
    15. painter.setWindow(QRect(0, 0, 210, 297)); //set coordinates in millimeters
    16.  
    17. painter.setPen(pen03);
    18. painter.drawLine(QLine(20, 50, 195, 50));
    19. painter.drawLine(QLine(195, 50, 195, 280));
    20. painter.drawLine(QLine(195, 280, 20, 280));
    21. painter.drawLine(QLine(20, 280, 20, 50));
    22. painter.drawLine(QLine(20, 57, 195, 57));
    23.  
    24. painter.setPen(pen01);
    25. painter.drawLine(QLine((wordX - 5), 50, (wordX - 5), 280));
    26. painter.drawLine(QLine((explX - 5), 50, (explX - 5), 280));
    27.  
    28. painter.setFont(arial10);
    29. painter.drawText(150, 50, "Testing"); // the font printed is *not* 10 points.
    30. ...
    31. painter.end();
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2008
    Location
    South Korea
    Posts
    14
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Text too big while printing after using SetWindow()

    Well, I still don't know how to set the size of the font using a point size, but I've found a solution that works for me.

    Instead of setting a point size, I used setPixelSize(). Even though the name in the function is Pixel, it actually corresponds nicely to the coordinate system I had set.
    I set the coordinate system to millimeters with SetWindow() (see above), and when I for example use font.setPixelSize(15), it produces a font on the printer of 15mm.
    I've tested this with various sizes, and they always correspond nicely to the size in millimeters...

    I don't know if this is the correct way to use these functions, but it works for my implementation.

    / Ingemar

  3. #3
    Join Date
    Feb 2008
    Location
    South Korea
    Posts
    14
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Text too big while printing after using SetWindow()

    I'm replying to myself here
    But I want to write about my findings, just in case somebody else is following this...

    One thing I realized is that by calling setWindow(QRect(0, 0, 210, 297)) above I'm actually limiting the page resolution to only 210 by 297 pixels!
    For lines it's "OK", but for text it's a disaster.
    When I printed text I noticed that the kerning (inter-character spacing) didn't space properly, the reason being that there was not enough horizontal resolution. Let's face it, 210 pixels resolution for the page width is not very good...

    I was thinking that a 10th of a millimeter might be OK, but even that is a little too low for kerning to function properly, so I decided to go for a 100th of a millimeter.
    My new call is now setWindow(QRect(0, 0, 21000, 29700))
    This way the kerning is working perfectly, I can still give my coordinates the way I want and the coordinates in my code are device-independant.

    I still haven't found a way to specify font size in points. If I try the fonts become HUGE, so I'm sticking to setPixelSize(), which works, but it feels wierd to specify font size in 100ths of a millimeter...

    / Ingemar

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 10:49
  2. Problem pasting text into a QTextEdit
    By Spockmeat in forum Qt Programming
    Replies: 8
    Last Post: 14th March 2009, 15:36
  3. QTextEdit slow to insert text
    By thomaspu in forum Qt Programming
    Replies: 4
    Last Post: 10th January 2008, 13:05
  4. Editable text in QGraphicsView
    By wysota in forum Qt Programming
    Replies: 8
    Last Post: 24th February 2007, 16:30
  5. Pixel Position and Printing text
    By nErnie in forum Qt Programming
    Replies: 1
    Last Post: 7th November 2006, 13:35

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.