【问题标题】:PyQT4 QTextBrowser auto-scrollPyQT4 QTextBrowser 自动滚动
【发布时间】:2015-10-05 09:39:23
【问题描述】:

我需要一点帮助。

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

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

我现在需要的是自动滚动到底部,这样我就可以看到正在发生的事情,而无需手动滚动到底部。

我试过了

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

但不工作。

有什么想法吗?

已修复!!!

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)

【问题讨论】:

    标签: python pyqt4 qtextbrowser


    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 2011-04-02
      • 2010-10-15
      • 2013-10-08
      • 2014-01-30
      • 2014-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-13
      相关资源
      最近更新 更多