1

I'm using a PyQt QTextBrowser widget that inherits from QTextEdit. I'm appending text to it as part of a display of logging information. The logging may go on for weeks.

What is the depth of the buffer that holds the text? Asked another way, how much text can I append and still have the user be able to scroll back to with the scroll bars?

Is this setting configurable? Could it eventually use all my system's ram?

Thanks.

JohnSantaFe
  • 145
  • 1
  • 3
  • 11

1 Answers1

5

There is no automatic management of the size of the text: it will just grow until the available memory runs out.

The simplest solution would probably be to set a fixed limit on the number of text blocks in the document:

logger.document().setMaximumBlockCount(5000)

This will start deleting blocks from the start of the document once the threshold has been passed. You will obviously have to work out for yourself what a safe maximum will be and/or make it a user-configurable setting.

Note that if you don't need rich-text formatting for the logging output, a QPlainTextEdit might be a better choice, since it is designed for exactly this sort of task.

ekhumoro
  • 115,249
  • 20
  • 229
  • 336