move qTextBrowser to Home Position
I have the folling code: (textBrowser is a QTextBrowser)
Code:
textBrowser->clear();
textBrowser->append("String with 100 lines of text");
textBrowser
->textCursor
().
movePosition(QTextCursor::Start);
textBrowser->ensureCursorVisible();
I thought this would make the beginning of the text visible for the user. But unfortunatly the cursor rest at the end of the text ( textBroser->textCursor().atEnd() returns true ).
I tried a work around with setting an named anchor at the beginning of the test, which works fine - but my app continues to write at the end. If I move to the beginning of the text with the keyboard pressing <ctrl+home> the windows stays very nice at the beginning - the anchor is some pixels lower, and the window continues to scroll.
now - how to move the window to the same state as <ctrl+home> does?
Thanks for your time,
Klaus
Re: move qTextBrowser to Home Position
Quote:
Originally Posted by klaus1111
I thought this would make the beginning of the text visible for the user. But unfortunatly the cursor rest at the end of the text
It doesn't work, because you operate on a copy of the cursor.
Quote:
QTextCursor QTextEdit::textCursor () const
Returns a copy of the QTextCursor that represents the currently visible cursor. Note that changes on the returned cursor do not affect QTextEdit's cursor; use setTextCursor() to update the visible cursor.
See also setTextCursor().
Re: move qTextBrowser to Home Position
yes - after your posting I must say, that it is clearly written in the documentation, which I have read at least 10 times before posting here. Funny - but sometimes you don't see what you see...
On the other hand - the behaviour is not 100% equal to the keyboard. When I move with the keyboard <ctrl+home> to the top, the textbrowser rest there, even if lines are appended to the end (what would be nice for my app in the moment). When I move with the "program" cursor, it now moves up, but in the moment where I append something the windows switchs back to the end. Does anybody has an idea about that?
Re: move qTextBrowser to Home Position
Quote:
Originally Posted by klaus1111
When I move with the "program" cursor, it now moves up, but in the moment where I append something the windows switchs back to the end.
Do you use QTextEdit::append() for this?
Maybe you should use another cursor?
Code:
cursor.insertText( "xxx" );