Создал тестовый пример
C++ (Qt)
#include <QtGui/QApplication>
#include <QtGui/QPrinter>
#include <QtGui/QPainter>
#include <QtGui/QPaintEngine>
#include <QtGui/QTextItem>
#include <QtGui/QFont>
#include <QtGui/QPrinterInfo>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QPrinter printer(QPrinter::HighResolution);
QPainter painter(&printer);
printer.setPrinterName(QPrinterInfo::defaultPrinter().printerName());
printer.setResolution(QPrinter::HighResolution);
printer.setOutputFormat(QPrinter::NativeFormat);
printer.setOrientation(QPrinter::Portrait);
printer.setPageSize(QPrinter::A4);
printer.setPaperSize(QPrinter::A4);
printer.setPaperSize(QSize(210,297),QPrinter::Millimeter);
qDebug(qPrintable("Page Rect Width "+QString::number(printer.pageRect().width())+
" Height "+QString::number(printer.pageRect().height())));
qDebug(qPrintable("Paper size in mm: Width "+QString::number(printer.paperSize(QPrinter::Millimeter).width())+
" Height "+QString::number(printer.paperSize(QPrinter::Millimeter).height())));
qDebug(qPrintable("Paper Size in device: Width "+QString::number(printer.paperSize(QPrinter::DevicePixel).width())+
" Height "+QString::number(printer.paperSize(QPrinter::DevicePixel).height())));
qDebug(qPrintable("Paper Size in 1/72 inhc: Width "+QString::number(printer.paperSize(QPrinter::Point).width())+
" Height "+QString::number(printer.paperSize(QPrinter::Point).height())));
qDebug(qPrintable("Painter size: Width "+QString::number(printer.widthMM())+
" Height "+QString::number(printer.widthMM())));
qDebug(qPrintable("Logical Resolution: X "+QString::number(printer.logicalDpiX())+
" Y "+QString::number(printer.logicalDpiY())));
qDebug(qPrintable("Phisical Resolution: X "+QString::number(printer.physicalDpiX())+
" Y "+QString::number(printer.physicalDpiY())));
painter.setRenderHint(QPainter::Antialiasing);
QRect paperRect(0,0,printer.paperSize(QPrinter::DevicePixel).width(),printer.paperSize(QPrinter::DevicePixel).height());
double dpiX = painter.paintEngine()->paintDevice()->logicalDpiX();
double dpiY = painter.paintEngine()->paintDevice()->logicalDpiY();
double m = (2.0/2.54)*printer.logicalDpiX();
QFont *font = new QFont("Courier New");
dpiX = printer.logicalDpiX();
dpiY = printer.logicalDpiY();
font->setPixelSize(dpiY*3/25.4); //24 //30 //38
font->setFixedPitch(true);
font->setBold(true);
font->setKerning(true);
font->setLetterSpacing(QFont::AbsoluteSpacing, dpiY*4/25.4 /*19.5*/); //17.5 //13.5 //8.5
painter.drawText(QPointF(dpiX*47/25.4, dpiY*21/25.4),"PRINT TEST");
QPen pen;
pen.setWidth(2);
painter.setPen(pen);
painter.drawLine(QPointF(dpiX*45/25.4,dpiY*19/25.4),QPointF(dpiX*260/25.4,dpiY*19/25.4));
painter.drawLine(QPointF(dpiX*45/25.4,dpiY*24/25.4),QPointF(dpiX*260/25.4,dpiY*24/25.4));
double d = 45;
for(int i=0; i<38; ++i){
painter.drawLine(QPointF(dpiX*(45+d*i)/25.4,dpiY*19/25.4),QPointF(dpiX*(45+d*i)/25.4,dpiY*24/25.4));
}
painter.drawLine(QPointF(dpiX*45/25.4,dpiY*26/25.4),QPointF(dpiX*260/25.4,dpiY*26/25.4));
painter.drawLine(QPointF(dpiX*45/25.4,dpiY*31/25.4),QPointF(dpiX*260/25.4,dpiY*31/25.4));
d = 45;
for(int i=0; i<38; ++i){
painter.drawLine(QPointF(dpiX*(45+d*i)/25.4,dpiY*19/25.4),QPointF(dpiX*(45+d*i)/25.4,dpiY*24/25.4));
}
painter.end();
return a.exec();
}
Отступ от левого края необходим 45 мм а на печати получаем 53 мм
Сверху отступ 19 мм, как и задан.
При этом позиция вывода текста заданная как 47 мм на 21 мм на печати выводит как 47 мм на 18 мм.