Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, August 2006
RE: Determining Character X Position


Message 1 in thread

Hello AndrÃ-

    Thank you very much for your reply and suggestion!  I currently cache
the x coordinates and check the previous line, the current line and the
next line(s) (ie. while there exists a nextline and next line has changed)
and resync the cache for each changed line using the cursor point.  I am
stumped on a way to avoid using the cursor point so frequently, or
preferably at all, as it can be quite expensive if several lines change
with a single key stroke.

    If you or anyone have some more ideas, I would appreciate your help very
much!

Thank you again for your help!
-Craig

>> I am trying to discover a means of determining the x coordinates of
>> characters inside a Qt widget that supports text editing.  I am currently
>> using a QMultiLineEdit, setting the cursor position and using
>> cursorPoint(), although this method is very expensive to use frequently. 
>> I do not believe to be able to use QFontMetrics.width() as I need to
>> support bi-directional text (in otherwords, I cannot assume that while
>> iterating character indices, that characters proceed left-to-right or
>> right-to-left).
> 
> Maybe going once through all positions and caching the x coordinates
> (and trying tho keep the cache in sync on subsequent changes) is an
> option for you.

--
 [ signature omitted ] 

Message 2 in thread

Craig Greenberg wrote:
> Hello André-
> 
>     Thank you very much for your reply and suggestion!  I currently cache
> the x coordinates and check the previous line, the current line and the
> next line(s) (ie. while there exists a nextline and next line has changed)
> and resync the cache for each changed line using the cursor point.  I am
> stumped on a way to avoid using the cursor point so frequently, or
> preferably at all, as it can be quite expensive if several lines change
> with a single key stroke.

I am convinced it is impossible to avoid entirely. 

And I've spent already more thoughts on exactly this issue than I wished:
In a former life I used to work on an Open Source, erm, 'document processor',
and providing a decent up/down cursor movement that works (a) as the user
expects, and (b) reasonably fast is definitely a challenge. 

It is a mess when chunks are non-uniform ('small' characters vs. 'big' images
or tables), and they are a pain when you need real '2D structured editing'
for things like formulas. Plain uniform text is reasonably easy to handle 
with the cache approach, though.

Regards
Andre'


--
 [ signature omitted ]