Increase Performance of Text and Large String



  • Hullo, hopefully a quick question.

    I'm creating an interface for a serial terminal. The text for that terminal is often growing in length, especially when something this happening.

    As its size increases, it becomes increasingly slow to update. I'm sure it has everything to do with the fact that it's a few thousand pixels high and growing every 50ms.

    Is there a better way to handle the text in this situation?

    If it helps, I'm currently using TextArea{} for this.



  • Are you updating whole text in your text area on new line?



  • Presumably it's laying out the entire text each time you update.
    To speed up text layouting, use the cheapest TextMode you can (PlainText preferably). It might be possible to disable kerning and hinting if you're using a monospaced font, I'm not sure. It's been a while since I delved into the text layout stuff, and to be honest, I hope to never see it again.

    Alternatively, split the text over multiple elements (perhaps newline delimited) - you could even use a stringlistmodel and a simple delegate for this. Just autoscroll to the most recently added delegate, and implement some data coalescing in your model to avoid delegate proliferation.

    Cheers,
    Chris.



  • Ah yeah, I like the multiple elements idea. I'll give it a test when I get back to that project. The main limitation of that method is not being able to select multiple lines to copy out (if needed).

    Thanks!



  • I suggest using the same text layout engine that Qt Creator uses, its optimized for huge amounts of text and only does layout of the stuff you see on screen.
    See the QPlainTextDocumentLayout class.
    Also see QTextEdit::document() and QTextDocument::setDocumentLayout().


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.