ibergmark
5th March 2008, 11:44
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:
printer = new QPrinter(QPrinter::PrinterResolution);
...
//set pens and fonts
QPen pen03;
pen03.setWidthF(0.3);
QPen pen01;
pen01.setWidthF(0.1);
QFont arial10("Arial", 10, QFont::Normal);
//draw the form
QPainter painter;
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();
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:
printer = new QPrinter(QPrinter::PrinterResolution);
...
//set pens and fonts
QPen pen03;
pen03.setWidthF(0.3);
QPen pen01;
pen01.setWidthF(0.1);
QFont arial10("Arial", 10, QFont::Normal);
//draw the form
QPainter painter;
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();