Dynamic text sizing and alignment based on screen resolution
-
Hi everyone, I'm having an issue with how to display text that I hope you may be able to help with.
I'm trying to display a title menu for a game, with six entries. Each would be a text string backed by a semi transparant backing and offset to the side of the screen to allow the artwork to show through. I am using the graphics view framework but manually drawing everything within the scene object myself because I want more depth layers than the framework offers.
I want to minimise how much space these entries take up while still making them human readable, so ideally I would like to do the following:
- Calculate 10% of the screen height and select an appropriate font matching this size, vertical alignment is handled using this as a step value.
- Calculate how wide the text entries will be utilising this font and then use the appropriate horizontal alignment based on this value.
- Render the text to the screen.
The second half of part (1) and part (2) have me really stumped at the moment. This is initially targetting Symbian but will be ported to desktop afterwards.
Thank you kindly for any help.
-
- maybe something like this:
@ QFont font("Arial");
font.setPointSize(14);
QFontMetrics fm(font);
qDebug()<<fm.width("1234")<<"pix";@
out:
44 pix - maybe something like this:
-
That's fantastic, thank you! I had completely missed the QFontMetrics class.