PDA

View Full Version : QTextEdit + auto scroll



jbpvr
7th March 2007, 21:35
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,

patrik08
7th March 2007, 22:52
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/viewvc/qt-webdav/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....

wysota
7th March 2007, 23:52
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:

QTextEdit *edit; // assuming this is your text edit
QScrollBar *sb = edit->verticalScrollBar();
sb->setValue(sb->maximum());

This should scroll the widget to the bottom...

mikhailt
9th March 2007, 11:08
DO:

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

GuS
22nd March 2008, 02:38
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:

QTextEdit *edit; // assuming this is your text edit
QScrollBar *sb = edit->verticalScrollBar();
sb->setValue(sb->maximum());

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.

wysota
22nd March 2008, 18:59
Move the cursor to the end.

GuS
23rd March 2008, 22:10
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.

wysota
25th March 2008, 09:30
Did you call ensureCursorVisible?