A code below creates a window with QTextBrowser
widget.
For five seconds the new lines of text added to QTextBrowser
using
its .insertPlainText()
method.
As soon as text fills an entire field QTextBrowser
automatically adds a scroll bar. But it does nothing to scroll down so the last line of text would be always visible (or readable) by the user.
I would like to know how to make QTestBrowser
scroll down automatically so the last line of the text is always within its text field or visible. How to achieve it?
Screenshot:
Code:
import sys, time
from PyQt4 import QtCore, QtGui
class MyDialog(QtGui.QDialog):
def __init__( self, parent = None ):
super(MyDialog, self).__init__(parent)
self._console = QtGui.QTextBrowser(self)
layout = QtGui.QVBoxLayout()
layout.addWidget(self._console)
self.setLayout(layout)
def updateField(self):
for m in range(5):
for n in range(100):
self._console.insertPlainText('%s : '%n)
QtGui.qApp.processEvents()
time.sleep(1)
if ( __name__ == '__main__' ):
app = None
if ( not QtGui.QApplication.instance() ):
app = QtGui.QApplication([])
dlg = MyDialog()
dlg.show()
dlg.updateField()
if ( app ): app.exec_()