PDA

View Full Version : QTextEdit slow to insert text



thomaspu
9th January 2008, 23:27
I've got an application that uses a QTextEdit that gets text inserted in it, often only 4-20 characters at a time quite frequently. Normally, I'm setting a different color, inserting about 20 characters, changing colors, inserting more text, etc. Problem is that the text inserts pretty slowly. I'd say it takes about 100 lines of differently colored text about 1sec to be drawn in. Thats running on my laptop ~PentiumM 1.7Ghz. It just seems really, really slow. As far as I can tell, it seems to be a problem with the QTextEdit just being slow. I read somewhere that theres some horrible performance issues with the scrollbars. I'm trying to append text to the QTextEdit and keep the QTextEdit scrolled down to the bottom of the text, So I'm often calling

QTextEdit->verticalScrollbar->setValue( mp_scrollBar->maximum() );
I'm inserting all plaintext, no HTML by the QTextEdit's insertPlainText method... Am I doing this the wrong way? Should I be inserting text into the QTextDocument that the QTextEdit uses instead? Or is the QTextEdit just slow for inserting new text?

Thanks,
Paul

wysota
9th January 2008, 23:45
Your method is fine. Are you sure the slowdown is caused by inserting text and nothing else?

thomaspu
10th January 2008, 01:10
That was stupid of me. I was calling qApp->processEvents() everytime text was inserted. I was doing that back when I was stepping through my code and wanted to see the updated text immediately. Removed the call and now it flys ;p

Paul

thomaspu
10th January 2008, 01:22
One related question. Is there a way to tell Qt to process GUI events for a specific widget? SO instead of saying qApp->processEvents() I could just do myWidget->processEvents() ??

Paul

wysota
10th January 2008, 12:05
You can use QCoreApplication::sendPostedEvents() if you want.