QTextEdit gets a performance problem when filling up

QTextEdit [doc.qt.nokia.com] is optimized for working with paragraphs and it is not designed for handling very large paragraphs. When having very long paragraphs you will run into a performance problem at some point, when this will happen depends on the speed of your machine, the font you are using etc. We are not planning to change this design since the users generally split their documents into paragraphs.

A solution to this problem can be to use a QPlainTextEdit [doc.qt.nokia.com] instead of a QTextedit and set the maximum number of blocks using setMaximumBlockCount() [qt.nokia.com].

1 comment

August 27, 2014

Picture of navsystems navsystems

Lab Rat

Feeble excuse!
If you want to display using setMaximumBlockCount then as stated you ONLY have the option of using QPlainTextEdit. If you need to display a scrolling log and can’t use a QListView or similar (for instance showing recent incoming messages of varying lengths, in different display modes e.g hex or plain text and also want to colour elements in the display then html seems a good choice. BUT you will run into performance issues here. While it is possible to remove old items from the view and mimic the partially working behaviour of setMaximumBlockCount which although implemented for QTextEdit is actually half broken and only works if you use plain text you will find that the business of inserting and removing text is a real performance bottleneck. You will be lucky if you can update an average screenful without running into huge performance issues. Yes it does seem to be down to fonts. Just take a look at this call stack …. QtGuid4.dll!QWidget::metric(QPaintDevice::PaintDeviceMetric m=PdmDpiY) Line 1664 + 0×1b bytes C++ QtGuid4.dll!QPaintDevice::logicalDpiY() Line 96 + 0×16 bytes C++ QtGuid4.dll!QFont::QFont(const QFont & font={…}, QPaintDevice * pd=0×0056bb08) Line 739 + 0×8 bytes C++ QtGuid4.dll!QTextEngine::font(const QScriptItem & si={…}) Line 1839 + 0×10 bytes C++
> QtGuid4.dll!QTextEngine::shapeTextWithHarfbuzz(int item=0) Line 1184 + 0×19 bytes C++ QtGuid4.dll!QTextEngine::shapeText(int item=0) Line 925 C++ QtGuid4.dll!QTextEngine::shape(int item=0) Line 1439 C++ QtGuid4.dll!QTextLine::layout_helper(int maxGlyphs=2147483647) Line 1753 C++ QtGuid4.dll!QTextLine::setLineWidth(double width=667.00000000000000) Line 1526 C++ QtGuid4.dll!QTextDocumentLayoutPrivate::layoutBlock(const QTextBlock & bl={…}, int blockPosition=9953, const QTextBlockFormat & blockFormat={…}, QTextLayoutStruct * layoutStruct=0×0051ba00, int layoutFrom=0, int layoutTo=16383, const QTextBlockFormat * previousBlockFormat=0×0051b808) Line 2619 C++ QtGuid4.dll!QTextDocumentLayoutPrivate::layoutFlow(QTextFrame::iterator it={…}, QTextLayoutStruct * layoutStruct=0×0051ba00, int layoutFrom=0, int layoutTo=16383, QFixed width={…}) Line 2406 C++ QtGuid4.dll!QTextDocumentLayoutPrivate::layoutFrame(QTextFrame * f=0×00585600, int layoutFrom=0, int layoutTo=16383, QFixed frameWidth={…}, QFixed frameHeight={…}, QFixed parentY={…}) Line 2145 C++ QtGuid4.dll!QTextDocumentLayoutPrivate::layoutFrame(QTextFrame * f=0×00585600, int layoutFrom=0, int layoutTo=16383, QFixed parentY={…}) Line 2049 + 0×27 bytes C++ QtGuid4.dll!QTextDocumentLayout::doLayout(int from=0, int oldLength=16383, int length=16383) Line 2939 + 0×25 bytes C++ QtGuid4.dll!QTextDocumentLayout::documentChanged(int from=0, int oldLength=16383, int length=16383) Line 2902 + 0×1e bytes C++ QtGuid4.dll!QTextDocumentPrivate::finishEdit() Line 1223 C++ QtGuid4.dll!QTextDocumentPrivate::endEditBlock() Line 1202 C++ QtGuid4.dll!QTextCursor::endEditBlock() Line 2496 C++ BSPMonitor.exe!BSPMonitor::updateDisplay(const NAVCOM_LOG_HDR * pMsg=0×00000000) Line 324 C++

Write a comment

Sorry, you must be logged in to post a comment.