I create my own Qt widget that mimics an A4 printed page, and I'm having trouble getting the right size fonts. My widget uses QPainter::setViewportand QPainter::setWindowto mimic an A4 page using units of 10 millimeters that allow me to easily draw. However, trying to create a font with a specific dot size does not work, and the use is QFont:setPixelSizeinaccurate. Here is the code:
View::View(QWidget *parent) :
QWidget(parent),
printer(new QPrinter)
{
printer->setPaperSize(QPrinter::A4);
printer->setFullPage(true);
}
void View::paintEvent(QPaintEvent*)
{
QPainter painter(this);
painter.setWindow(0, 0, 2100, 2970);
painter.setViewport(0, 0, printer->width(), printer->height());
painter.drawRect(100, 100, 600, 254);
QFont font("Arial");
font.setPixelSize(254);
painter.setFont(font);
painter.drawText(QRect(100, 100, 600, 254), tr("Wg\u0102"));
const QFontMetrics fontMetrics = painter.fontMetrics();
qDebug() << "Font height = " << fontMetrics.height();
}
So, I ask you to get 254 tall font (1 inch, 72 points), and it is too big and sure enough, when I request the font height through QFontMetrics, it is 283 high.
- , , ? . , , / (, Win32 DPtoLP/LPtoDP.)
: , , . , , , . , , .