Results 1 to 8 of 8

Thread: QTextEdit + auto scroll

  1. #1
    Join Date
    Feb 2007
    Posts
    13
    Thanks
    2

    Default QTextEdit + auto scroll

    I have a QTextEdit displaying data that is being written to a log file( at the same time)

    I would like for the new data that is being added to the QTextEdit to always be visible when
    new data is coming, but currently you have to scroll to the data to see it. Is there a way to have it scroll down to the bottom of the page always when data is being inserted.

    Thanks,

  2. #2
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTextEdit + auto scroll

    Quote Originally Posted by jbpvr View Post
    I have a QTextEdit displaying data that is being written to a log file( at the same time)

    I would like for the new data that is being added to the QTextEdit to always be visible when
    new data is coming, but currently you have to scroll to the data to see it. Is there a way to have it scroll down to the bottom of the page always when data is being inserted.

    Thanks,
    insert data at top .... like prepend .... or move connect to a http://doc.trolltech.com/4.2/qscrollbar.html
    example to connect on ...
    http://qt-webdav.svn.sourceforge.net...v/html_editor/
    svn co https://qt-webdav.svn.sourceforge.net/svnroot/qt-webdav qt-webdav

    on this small html editor 2 QTextEdit is connected to display line nr on source view....

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

    jbpvr (8th March 2007)

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextEdit + auto scroll

    Probably the simplest way is to call QTextEdit::ensureCursorVisible() after adding some text to the text edit. In case you don't have a cursor (for example when the widget is read only), you might try this combination instead:
    Qt Code:
    1. QTextEdit *edit; // assuming this is your text edit
    2. QScrollBar *sb = edit->verticalScrollBar();
    3. sb->setValue(sb->maximum());
    To copy to clipboard, switch view to plain text mode 

    This should scroll the widget to the bottom...

  5. The following user says thank you to wysota for this useful post:

    jbpvr (8th March 2007)

  6. #4
    Join Date
    Mar 2006
    Posts
    8
    Thanks
    1
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextEdit + auto scroll

    DO:

    pTextEdit->insertPlainText(strText);
    QTextCursor c = pTextEdit->textCursor();
    c.movePosition(QTextCursor::End);
    pTextEdit->setTextCursor(c);

  7. The following 2 users say thank you to mikhailt for this useful post:

    Camus SoNiCo (3rd January 2008), jml (26th February 2008)

  8. #5
    Join Date
    Mar 2006
    Location
    Argentina - CABA
    Posts
    66
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Platforms
    Unix/X11

    Default Re: QTextEdit + auto scroll

    Quote Originally Posted by wysota View Post
    Probably the simplest way is to call QTextEdit::ensureCursorVisible() after adding some text to the text edit. In case you don't have a cursor (for example when the widget is read only), you might try this combination instead:
    Qt Code:
    1. QTextEdit *edit; // assuming this is your text edit
    2. QScrollBar *sb = edit->verticalScrollBar();
    3. sb->setValue(sb->maximum());
    To copy to clipboard, switch view to plain text mode 

    This should scroll the widget to the bottom...
    Hi!

    I' have a same behaviour with QTextEdit (which contain html text). It has chat functions. I load a GUI inside my code, which allready has a QTextEdit and a alwaysOn vertical scrollbar.
    How I could autoscroll it to the end?

    Thanks.

    Cheers.
    Gustavo A. DÃ*az
    artistic.gdnet.com.ar

  9. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextEdit + auto scroll

    Move the cursor to the end.

  10. #7
    Join Date
    Mar 2006
    Location
    Argentina - CABA
    Posts
    66
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Platforms
    Unix/X11

    Default Re: QTextEdit + auto scroll

    You mean with this example above?

    pTextEdit->insertPlainText(strText);
    QTextCursor c = pTextEdit->textCursor();
    c.movePosition(QTextCursor::End);
    pTextEdit->setTextCursor(c);
    Cause i did this (with PyQt) and din't worked...

    Cheers.
    Gustavo A. DÃ*az
    artistic.gdnet.com.ar

  11. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextEdit + auto scroll

    Did you call ensureCursorVisible?

Similar Threads

  1. QTextEdit, sizeHint, QWidget
    By TheKedge in forum Qt Programming
    Replies: 1
    Last Post: 3rd February 2007, 08:25
  2. QScrollArea's Scroll Bars
    By ToddAtWSU in forum Qt Programming
    Replies: 5
    Last Post: 19th September 2006, 13:27
  3. QTextEdit API questions (plain text)
    By Gaspar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 06:03
  4. Retrieving offsets of scroll in QWorkspace
    By hardgeus in forum Qt Programming
    Replies: 6
    Last Post: 9th May 2006, 02:25
  5. [QT 4] QTextEdit performance
    By fellobo in forum Qt Programming
    Replies: 8
    Last Post: 6th March 2006, 19:27

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.