Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable size font #49

Open
MCVitzz opened this issue Apr 26, 2020 · 3 comments
Open

Variable size font #49

MCVitzz opened this issue Apr 26, 2020 · 3 comments

Comments

@MCVitzz
Copy link

MCVitzz commented Apr 26, 2020

Hello, not sure if here is the best place to ask this, but is there any way to make the font scale according to it's bounding box?

@opcon
Copy link
Owner

opcon commented Apr 27, 2020

Hi @MCVitzz,

No, there is no functionality for this built in.
You can get the width & height of some text with the Measure method on QFont (within some bounding box maxSize), but that doesn't really help as generating a new QFont object with a different font size is a reasonably expensive operation.

What is your use case for the font scaling? If it is scaling the GUI to match different resolutions then you can set the projection matrix on QFontDrawing to match your GUI projection matrix and scale with that.

Otherwise if you need to dynamically scale your font size to fit either a changing amount of text, or a changing bounding box size, it is a bit trickier.
One thing you could try is setting a few font sizes as "breakpoints", and switching between them as the bounding box gets filled up? e.g., have QFont objects for, say, 12, 16, 20, 24, 28pt, start at the largest size & work your way down when the bounding box is full?

@MCVitzz
Copy link
Author

MCVitzz commented Apr 27, 2020

Hello,
Yes, it's the GUI Scaling issue, I'm trying to have scaling GUI and variable resolution screens, I'm using the projection matrix already and updating it to the current resolution, I also have a follow up question, is it possible to center the text vertically with the bounding box? I've search for it in the options but I might have missed something...
Thank you for all the help!

@opcon
Copy link
Owner

opcon commented Apr 29, 2020

To center the text vertically you will need to get the text height (from a Measure call) and then apply the offset manually

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants