How do I convert my font on a QGraphicsObject
from point size to pixel size? I need to do this so the fonts will look right when I print my QGraphicsScene
using QGraphicsScene::render()
.
how to calculate qfont pixel size from point size
Probably class QFontMetrics will do the job. Just create your desired QFont, set It's point size. Then create QFontMetrics object on your QFont.
I'm having trouble figuring out how to use QFontMetrics to do this. I've also looked at QFontInfo, which does give me the current pixel size, but I'm not sure what to do with it. So far, font.setPixelSize(font.pointSize()) seems to work, but I don't know why - doesn't seem like it will be reliable. Thoughts? –
Epley
font.setPointSize(yourPointSize); QFontMetrics fm(font); fm.height() <- this will give you font height in pixels. Point size is DPI dependent. So probably at your dpi 1px is near 1point size. –
Cleodel
© 2022 - 2024 — McMap. All rights reserved.
render()
call work for you? – Venationrender
produces correct results for everything except text. My fonts are specified in points, and the defaultrender()
, when I pass it aQPainter
created from myQPrinter
, makes the font huge. Here's my original question: #3680337 – Epley