Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Always show the end of QTextBrowser
QtWS25 Last Chance

[Solved] Always show the end of QTextBrowser

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 18.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Fahmy
    wrote on 18 Dec 2011, 07:17 last edited by
    #1

    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);@

    Stay hungry, stay foolish.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on 18 Dec 2011, 14:05 last edited by
      #2

      Something like this should do the trick:

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

      [Brain to terminal, not tested.]

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on 18 Dec 2011, 14:25 last edited by
        #3

        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.

        1 Reply Last reply
        0
        • F Offline
          F Offline
          Fahmy
          wrote on 19 Dec 2011, 08:44 last edited by
          #4

          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]

          Stay hungry, stay foolish.

          1 Reply Last reply
          0

          2/4

          18 Dec 2011, 14:05

          • Login

          • Login or register to search.
          2 out of 4
          • First post
            2/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved