valicode
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2016
02:34 PM
Determining text width on a Label (SDK2)
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.
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.
6 REPLIES 6
juantwc
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2016
12:22 AM
Re: Determining text width on a Label (SDK2)
Any luck with this?
valicode
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2016
06:59 AM
Re: Determining text width on a Label (SDK2)
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!
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
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2016
12:02 PM
Re: Determining text width on a Label (SDK2)
This would definitely be useful.
brybott
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2016
01:54 PM
Re: Determining text width on a Label (SDK2)
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
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2016
12:28 AM
Re: Determining text width on a Label (SDK2)
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"]
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
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2016
12:18 AM
Re: Determining text width on a Label (SDK2)
Thanks for the workaround man, it is working well 🙂