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()
.
views:
94answers:
1
+1
A:
Probably class QFontMetrics will do the job. Just create your desired QFont, set It's point size. Then create QFontMetrics object on your QFont.
Kamil Klimek
2010-09-13 16:27:19
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?
David Burson
2010-09-13 17:19:24
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.
Kamil Klimek
2010-09-14 19:06:34