The problem is probably caused by QTBUG-44765 fixed in Qt 5.5.
Given the low error rate, I do not think that this can be practically circumvented.
You can get around this by adding an empty line to TextEdit when you finish syntax highlighting
TextEdit { id: captionTextEdit width: wrapperFlick.width height: wrapperFlick.height text: display readOnly: true Component.onCompleted: { itemsModel.initHighlighter(index, captionTextEdit.textDocument) } Connections { target: itemsModel onUpdateTextEdit: { console.log("Update element at index: " + indexToUpdate) if (indexToUpdate == index) { console.log("Update me!") captionTextEdit.append("") } } } onCursorRectangleChanged: wrapperFlick.ensureVisible(cursorRectangle) }
where updateTextEdit(indexToUpdate) is the new signal your Model element should emit.
itemsmodel.h
signals: void updateTextEdit(int indexToUpdate);
itemsmodel.cpp
void ItemsModel::initHighlighter(int index, QQuickTextDocument *document) { // Signal mapper could be avoided if lamda slot are available (Qt5 and C++11) QSignalMapper* signalMapper = new QSignalMapper(this); if (0 <= index && index < m_ItemsList.length()) { SingleItem *item = m_ItemsList.at(index); SpellCheckHighlighter *highlighter = new SpellCheckHighlighter(document->textDocument(), item); QObject::connect(item, SIGNAL(spellCheckResultsReady()), highlighter, SLOT(rehighlight())); // TODO: Don't connect this slot for Qt 5.5+ to avoid performance overhead QObject::connect(item, SIGNAL(spellCheckResultsReady()), signalMapper, SLOT(map())); signalMapper->setMapping(item, index); } connect(signalMapper, SIGNAL(mapped(int)), this, SIGNAL(updateTextEdit(int))); }
The full code is available here: https://bitbucket.org/swarta/rehighlighdemo/branch/workaround#diff
Simon warta
source share