[Solved] Always show the end of QTextBrowser



  • Ini my app, I use QTextBrowser to redirect stdout. But the problem is QTextBrowser always show the top of text rather than the end.

    So, everytime a new line inserted. I need to scroll to the end to read the latest line. How can I fix this? I've already used movecursor. But still no luck.

    @ QByteArray byteTerminal = processObject->readAll();
    textTerminal = textTerminal.append(byteTerminal); //textTerminal is a QString.
    ui->terminalTextBrowser->moveCursor(QTextCursor::End);
    ui->terminalTextBrowser->setText(textTerminal);@



  • Something like this should do the trick:

    @
    QScrollBar *sb = ui->terminalTextBrowser()->verticalScrollBar();
    sb->setValue(sb->maximum());
    @

    [Brain to terminal, not tested.]



  • Yeah, that ought to work, though I guess there are other methods with scrolling to a cursor or something like that. Anyway, you probably do want to make sure that you only do this auto-scrolling if the scrollbar already was at the end before you add new text. That way, if the user is looking at a section of the log, it won't just scroll away from the section he was looking at because you are adding a new line to the log.



  • Thanks a lot. It works!

    Ps. Just change terminalTextBrowser() to terminalTextBrowser.

    [quote author="Volker" date="1324217111"]Something like this should do the trick:

    @
    QScrollBar *sb = ui->terminalTextBrowser()->verticalScrollBar();
    sb->setValue(sb->maximum());
    @

    [Brain to terminal, not tested.][/quote]


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.