Results 1 to 4 of 4

Thread: move qTextBrowser to Home Position

  1. #1
    Join Date
    Jan 2006
    Location
    Stuttgart
    Posts
    10
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default move qTextBrowser to Home Position

    I have the folling code: (textBrowser is a QTextBrowser)
    Qt Code:
    1. textBrowser->clear();
    2. textBrowser->append("String with 100 lines of text");
    3. textBrowser->textCursor().movePosition(QTextCursor::Start);
    4. textBrowser->ensureCursorVisible();
    To copy to clipboard, switch view to plain text mode 
    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default 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.

    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().

  3. The following user says thank you to jacek for this useful post:

    klaus1111 (15th July 2006)

  4. #3
    Join Date
    Jan 2006
    Location
    Stuttgart
    Posts
    10
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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?

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default 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?
    Qt Code:
    1. QTextCursor cursor( _ui.textEdit->textCursor() );
    2. cursor.movePosition( QTextCursor::End );
    3. cursor.insertText( "xxx" );
    To copy to clipboard, switch view to plain text mode 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.