PyQT4 QTextBrowser自动滚动

Tia*_*osé 5 python pyqt4 qtextbrowser

我需要一点帮助。

我有这个QTextBrowser,我将所有标准输出重定向到它。

self.console_window = QtGui.QTextBrowser()
self.console_window.setReadOnly(True)
Run Code Online (Sandbox Code Playgroud)

我现在需要的是自动滚动到底部,因此无需手动滚动到底部就可以看到正在发生的情况。

我试过了

 scrollBar = self.console_window.verticalScrollBar()
 scrollBar.setValue(scrollBar.maximum())
Run Code Online (Sandbox Code Playgroud)

但不起作用。

有什么想法吗?

固定!!!

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)
Run Code Online (Sandbox Code Playgroud)

Dan*_*ski 1

只是 Pyqt5 的快速更新。

我的做法有点不同,因为我发现需要延迟:

            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
Run Code Online (Sandbox Code Playgroud)