[Gambas-user] TextWidth

Benoît Minisini gambas at ...1...
Sat Sep 4 02:27:05 CEST 2010


> Fabián Flores Vadell ha scritto:
> > When I try to adjust the width of a TextBox to its content, I use
> > txtSomeThing.Width = txtSomeThing.TextWidth(txtSomeThing.Text). But
> > doing that, the width of TextBox never be enought to show its content
> > completely.
> > 
> > I tried to find a correction factor but this is a fallible method. How
> > I can adjust exactly the width of a TextBox to its content?
> 
> The width of a widget refers to its outside width, including
> decorations. The interior width is a different thing, sometimes called
> ClientWidth; but I don't know if Gambas TextBoxes have a ClientWidth
> property. The size of the decorations should be always the same (in a
> given theme). I don't know how to calculate it but, supposed that this
> is possible and this is "8", something like
> 
>     txtSomeThing.Width = 8 + txtSomeThing.TextWidth(txtSomeThing.Text)
> 
> could work, but I am not sure.
> 
> Regards,
> Doriano
> 

I couldn't find a better solution than Doriano, because there is no easy way 
to know the size of a control border in Qt and GTK+.

Moreover, I don't see the need of adjusting a TextBox to its contents, as 
usually this is an editable control, and so the user can enter any text in it. 
Or maybe you are doing something not usual with a TextBox? :-)

-- 
Benoît Minisini




More information about the User mailing list