views:

94

answers:

1

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().

+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
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
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