[Solved] Size an edit widget to the text

shenjoku

07-09-2011 03:42:38

I'm trying to figure out a way to size an Edit widget to the size of the text inside of it. The widget is clamped at the parent size and word wrap is enabled so all I need now is to make the height of the Edit widget update so it fits however tall the text ends up being. Is there any way to do this? I haven't found any obvious solutions yet.

EDIT: Found a solution after looking around for a while. After setting the text on the Edit widget using setCaption() if you use editWidget->getHeight() + editWidget()->getVScrollRange() you will get the height needed to fit the text.

Altren

07-09-2011 08:44:16

Also there is getTextSize() method in all widgets with text area.

shenjoku

25-10-2011 04:11:49

Ah, I don't know how I missed that. That should make the code a bit cleaner. Thanks :)