W
W
w0lkolak2020-10-05 22:08:45
Syntax highlighting
w0lkolak, 2020-10-05 22:08:45

Why does setFormat in hightlight take 20 times longer when opening a document than when inserting text?

Given:
Yes . It is set in __init__ among other thingsclass MyEdit(QPlainTextEdit)

self.highlight = HL_Syntax.GMHighlighter(self.document())

Is , for which it is overriddenclass GMHighlighter (QSyntaxHighlighter)
def highlightBlock(self, text):
...
self.setFormat(index, length, format)


And there is also a document for syntax highlighting for a million lines.
Now, actually, an unclear moment:
Without
self.highlight = HL_Syntax.GMHighlighter(self.document())

it takes 6 seconds to cleanly open and place MyEdit a millionaire file , it takes 14 seconds to insert the same text into an empty one . That is, everything is relatively fast, but opening is faster than Ctrl + V . If you turn on syntax recognition, but do not turn on visual highlighting (without ), then 35 seconds are added to both results , which is logical. However, it is worth turning it on and strangeness begins - Ctrl + V adds another six seconds , and opening the file instantly slows down at times and takes more than three minutes .MyEdit
setFormat
self.setFormat(index, length, format)
That is, creating a new file and pasting text into it becomes faster than opening a text file, although opening itself took less time than pasting.
Found that the problem exists when using self.updateRequest.connect(self.updateLineNumberArea) and seFormat at the same time, where
def updateLineNumberArea(self, rect, dy):
        if dy:
            self.lineNumberArea.scroll(0, dy)
        else:
            self.lineNumberArea.update(0, rect.y(), self.lineNumberArea.width(), rect.height())
        if rect.contains(self.viewport().rect()):
            self.updateLineNumberAreaWidth(0)

Why is this happening and what can help me?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question