Your Digital Media Has Never Looked So Good

 
valicode
Topic Author
Posts: 10
Joined: Tue Oct 27, 2015 4:29 am

Determining text width on a Label (SDK2)

Thu Jan 07, 2016 3:34 pm

Hello,

Is there any way to determine or calculate the text width of the rendered text on a Label using SDK2 / Scene Graph Components?

Thanks in advance for any advice.
 
juantwc
Posts: 15
Joined: Thu Nov 26, 2015 3:23 am

Re: Determining text width on a Label (SDK2)

Mon Feb 08, 2016 1:22 am

Any luck with this?
 
valicode
Topic Author
Posts: 10
Joined: Tue Oct 27, 2015 4:29 am

Re: Determining text width on a Label (SDK2)

Mon Feb 08, 2016 7:59 am

Hello juantwc, I saw your post at the end of Beta Scene Graph components and it reminded me to check this thread as well.

No - I have not found a work-around to this yet. I will update this thread once a fix has been found. I encourage you to do the same if you find it first.

Cheers!
 
brybott
Posts: 40
Joined: Wed Feb 04, 2015 5:17 pm

Re: Determining text width on a Label (SDK2)

Mon Feb 08, 2016 1:02 pm

This would definitely be useful.
 
brybott
Posts: 40
Joined: Wed Feb 04, 2015 5:17 pm

Re: Determining text width on a Label (SDK2)

Mon Feb 08, 2016 2:54 pm

So, I think a rough answer that could be used as a work around, is that if you can update the label from the main thread, you could determine the size via roFont's GetOneLineWidth, and take the result of that and use it to set the width of your label node.
 
valicode
Topic Author
Posts: 10
Joined: Tue Oct 27, 2015 4:29 am

Re: Determining text width on a Label (SDK2)

Mon Apr 25, 2016 12:28 am

Just updating this with our current workaround:

Set the label width to 0, or not at all
Set the font and size
Set the text, then:

bounding = label.boundingRect()
labelWidth = bounding["width"]

You will still need to set the label width as follows (otherwise it stays at 0)
label.width = bounding["width"]
 
apl001
Posts: 1
Joined: Mon Apr 18, 2016 10:25 pm

Re: Determining text width on a Label (SDK2)

Wed May 25, 2016 12:18 am

Thanks for the workaround man, it is working well :)

Who is online

Users browsing this forum: No registered users and 7 guests