Page 1 of 1

Text length in pixels

Posted: 13 Dec 2017 08:34
by digitalstone
Is there a way to get the amount of pixels (length and height) based off the text being showed?

I'm creating a global message box.

Re: Text length in pixels

Posted: 13 Dec 2017 15:54
by Desmanto
Quite to difficult to do, even though I think it is possible.
Maybe the better way is to get the bound x,y of the element id.
What is the purpose of getting the amount of pixel from the message box?

Re: Text length in pixels

Posted: 13 Dec 2017 18:18
by digitalstone
Desmanto wrote:Quite to difficult to do, even though I think it is possible.
Maybe the better way is to get the bound x,y of the element id.
What is the purpose of getting the amount of pixel from the message box?
What do you mean with the element id?
I'm building the messagebox based on a widget btw

Getting the amount of pixels is to determine the dimensions of the message box.
I like things to be futureproof while not taking up more space than needed.
But i guess i could make it just 1 size for every possible message ever if it's not possible.

Re: Text length in pixels

Posted: 14 Dec 2017 05:19
by Desmanto
Oh, I thought you wanna retrieve the size in certain UI Element. Measuring the text pixel seems quite difficult unless you use monospace font. Non-monospace font has kerning, which makes the length varies depend on the content. Counting based on the number of char will give only rough estimation.

So maybe you can use rough estimation based on the char count.

Re: Text length in pixels

Posted: 14 Dec 2017 17:42
by digitalstone
Alright thanks.
Already thought it was more difficult than worthy of implementation.

I'll just see what i can do with a monospace font, if i can setup any that is. But i'll check it out.

Re: Text length in pixels

Posted: 09 Jan 2018 15:40
by digitalstone
Btw, Monospace is the fontname.
It's right inside the font options of the widget.