how to calculate qfont pixel size from point size
Asked Answered
E

1

7

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

Epley answered 13/9, 2010 at 15:34 Comment(2)
What are you looking for in the end result? Why doesn't the default render() call work for you?Venation
I want the scene to be printed on paper, and look like it does on the screen. The default render produces correct results for everything except text. My fonts are specified in points, and the default render(), when I pass it a QPainter created from my QPrinter, makes the font huge. Here's my original question: #3680337Epley
C
10

Probably class QFontMetrics will do the job. Just create your desired QFont, set It's point size. Then create QFontMetrics object on your QFont.

Cleodel answered 13/9, 2010 at 16:27 Comment(2)
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.