[Gambas-user] difference between QT TextEdit.Select and TextArea.Select

Benoit Minisini gambas at ...1...
Fri Jan 18 22:40:56 CET 2008


On vendredi 18 janvier 2008, Benoit Minisini wrote:
> On jeudi 17 janvier 2008, Jaap Cramer wrote:
> > HI
> >
> > I discovered a inconvenient difference between the behavior of Method
> > SELECT in TextEdit and TextArea. By a TextArea properties like POS can be
> > used in the method SELECT. If the text contains Unicode the value of the
> > cursor-position can be recalculated to the position in the string. This
> > is not the case in TextEdit. Because TextEdit contains HTML-tags, the
> > cursor position cannot be used, or recalculated to a position in the
> > string. Is this an error in TextEdit.Select; I want to select text, not
> > positions...
> >
> > I added a example snippet to illustrate. The following code is called on
> > tBible_MouseUp(). If one changed the position of the cursor, the purpose
> > is to select the word on a single click. The following snippet works fine
> > if tBible is a TextArea. I want to add some markups, so I decided to
> > change tBible into a TextEdit.
> >
> >   DIM iPos, iStart, iEnd AS Integer
> >   DIM sB AS String                 ' a temp container for the contents of
> > tBible.text
> >
> >   sB = tBible.Text & " "            'end of text and space, so each word
> > is surrounded by spaces sB = Replace(sB, "\n", " ")    'consider a return
> > as a space
> >   sB = Replace(sB, "־", " ")      'consider 'maqqef' (the high
> > division-marker) as space
> >
> >   IF tBible.Selection.Length = 0 THEN           'if there is already a
> > selection, then don't change it! iPos = tBible.Pos
> >           'Position of the CURSOR, not string, so I don't need to
> > recalculate it from a unicode string iStart = String.RInStr(sB, " ",
> > iPos) 'working with unicode, so recalculate values iEnd =
> > String.InStr(sB, " ", iPos) - 1
> >     tBible.Select(iStart, iEnd - iStart)
> >   ENDIF
> >
> >
> > grt
> > Jaap
> >
> > Ubuntu 7.10, Gambas 2.0.0
>
> There is really a problem with the TextEdit interface, and it comes from
> the way the QT widget it is based on works.
>
> Maybe I should try to split the Text property, and have:
> * Text for returning the text.
> * RichText for returning the text with the markups.
> * Selection.Text for returning the selected text.
> * Selection.RichText for returning the selected text with the markups.
>
> But I don't know if it is possible. Stay tune...

It works. But you get it only in the development version, not in the stable 
one.

-- 
Benoit Minisini




More information about the User mailing list