PyQT4 QTextBrowser自动

2024-10-01 13:26:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要一点帮助。在

我有一个QTextBrowser,在这里我将所有stdout重定向到它。在

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

我现在需要的是自动滚动到底部,这样我就可以看到发生了什么,而不需要手动滚动到底部。在

我试过了

^{pr2}$

但不起作用。在

有什么想法吗?在

已修复!!!

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)

Tags: textselftruedefstdout手动window重定向
1条回答
网友
1楼 · 发布于 2024-10-01 13:26:11

只是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

相关问题 更多 >