JohnSantaFe
JohnSantaFe

Reputation: 155

PyQt depth of QTextEdit buffer

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.

Upvotes: 1

Views: 1374

Answers (1)

ekhumoro
ekhumoro

Reputation: 120638

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.

Upvotes: 5

Related Questions