PDA

View Full Version : Autoscroll QTextBrowser



aLiNuSh
23rd March 2007, 20:24
Hi,

I'm making this chat window and I implemented the chat board with a QTextBrowser. I'm new to Qt so if there's a better way to do it please say so.

What I want to do, is to make the textBrowser scroll down when there's no space left for new messages. Right now if I send like 50 messages to the board, the scrollbar appears but it doesn't scroll down and I can't see the rest of the messages unless I scroll manually which is not user friendly.

So is there anyway to make the QTextBrowser scroll down automatically each time text is inserted? Or maybe I should use another widget that can do that?

Many thanks :)

wysota
23rd March 2007, 22:11
Please search the forum. A simmilar issue was brought up not more than two weeks ago.

aLiNuSh
24th March 2007, 09:40
I did and found nothing, I'll keep searching then :(

wysota
24th March 2007, 09:46
http://www.qtcentre.org/forum/f-qt-programming-2/t-qtextedit-auto-scroll-5983.html

aLiNuSh
24th March 2007, 12:27
Thanks for the link :)
I've solved it now

Here's how...



void MainChatDlg::on_send_pushButton_clicked ()
{
if (!message_lineEdit->text().isEmpty ())
{
conversation_textBrowser->insertPlainText('\n' + message_lineEdit->text ());
QScrollBar *sb = conversation_textBrowser->verticalScrollBar();
sb->setValue(sb->maximum());
message_lineEdit->clear ();
}
}