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:
Code:
...
//set pens and fonts
pen03.setWidthF(0.3);
pen01.setWidthF(0.1);
//draw the form
painter.begin(printer);
painter.
setWindow(QRect(0,
0,
210,
297));
//set coordinates in millimeters
painter.setPen(pen03);
painter.
drawLine(QLine(20,
50,
195,
50));
painter.
drawLine(QLine(195,
50,
195,
280));
painter.
drawLine(QLine(195,
280,
20,
280));
painter.
drawLine(QLine(20,
280,
20,
50));
painter.
drawLine(QLine(20,
57,
195,
57));
painter.setPen(pen01);
painter.
drawLine(QLine((wordX
- 5),
50,
(wordX
- 5),
280));
painter.
drawLine(QLine((explX
- 5),
50,
(explX
- 5),
280));
painter.setFont(arial10);
painter.drawText(150, 50, "Testing"); // the font printed is *not* 10 points.
...
painter.end();
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
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