[Qt-interest] QTextEdit/QTextBrowser: how to _really_ save/restore position (cursorForPosition() fails with tables)?

Esben Mose Hansen kde at mosehansen.dk
Sat Jun 5 06:25:34 CEST 2010


On Friday 04 June 2010 19:13:49 Louis Semprini wrote:
> 2. is there an alternate method rather than saving and restoring
> QTextCursor  position?

I am no expert in this, but I assume you are using

QTextCursor QTextEdit::textCursor () const

to save the cursor position and 

void   setTextCursor ( const QTextCursor & cursor )

to restore it? So where do cursorForPosition() come into it?

Anyway, cursorForPosition() returns the position for /viewport/ coordinates, 
which means that 0,0 would always be the top of the document. So you probably 
want to translate the 0,0 to viewportcoordinates using something like 
textBrowser->verticalScrollBar()->value() if going by that route. 

But for my money, I'd just store the 2 values for the scrollbars, and the 
value of textCursor(), and the set all thos when restoring. It should work.

-- 
Kind regards, Esben



More information about the Qt-interest-old mailing list