[Gambas-user] Control widths, fonts, desktop scales, strings and a bad memory

Fabien Bodard gambas.fr at gmail.com
Tue Sep 4 18:47:55 CEST 2018


well :

http://gambaswiki.org/wiki/comp/gb.qt4/paint/trimrichtext



Le mar. 4 sept. 2018 à 11:53, Me <adamnt42 at gmail.com> a écrit :

> Well, 12 working hours* later I have found an approximate solution!
> 1. Get the Control.Font.TextWidth(<text>)
> 2. Divide that by the Len(<text>) giving a "magic" number - call it the
> average character width
> 3. Calculate a test value being ((Control.Width - Desktop.Scale) / $magic)
> being the number of average characters that might fit.
> 4. Subtract a safety margin from the test value (say 6 chars)
> 5. Truncate the text and add " ..."
> 6. Bingo! It fits!
>
> Seems to work so far for a dozen or so fonts and font sizes I've tried. I
> built a little calculator while I was working through this. A
> couple of screen shots are attached.
>
> *That 12 hours Included reading a lot of QT documentation! Talk about
> never use a sentence when a chapter will do.
>
> Thanks for all the input.
> b
> --
> Me <adamnt42 at gmail.com>
>
> ----[ Gambas mailing-list is hosted by https://www.hostsharing.net ]----
>


-- 
Fabien Bodard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20180904/bff4273b/attachment.html>


More information about the User mailing list