Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyQT4 QTextBrowser auto-scroll

I need a little help here.

I have this QTextBrowser where I redirect all stdout to it.

self.console_window = QtGui.QTextBrowser()
self.console_window.setReadOnly(True)

What I need now is to auto scroll to the bottom so I can see what is happening without the need of manually scroll to the bottom.

I tried this

 scrollBar = self.console_window.verticalScrollBar()
 scrollBar.setValue(scrollBar.maximum())

but is not working.

Any thoughts?

FIXED!!!

def handleOutput(self, text, stdout):
        self.console_window.moveCursor(QtGui.QTextCursor.End)
        self.console_window.ensureCursorVisible()
        self.console_window.insertPlainText(text)


    def Console_Window(self):
        self.console_window = QtGui.QTextEdit()
        self.console_window.setReadOnly(True)
like image 721
Tiago São José Avatar asked Nov 10 '22 04:11

Tiago São José


1 Answers

just a quick update in Pyqt5.

i did it bit differently, as i've seen that a delay is needed:

            self.scrollbar = self.log_output.verticalScrollBar() #the self.scrollbar is the same as your self.console_window

            try:
                time.sleep(0.1) #needed for the refresh
                self.scrollbar.setValue(10000) #try input different high value

            except:
                pass #when it is not available
like image 82
Danny Kaminski Avatar answered Nov 25 '22 13:11

Danny Kaminski