【发布时间】:2021-05-30 15:05:00
【问题描述】:
因为我想要使用的突出显示需要在上一行的变量中获取存储的先前状态,我可以通过将其存储在 setCurrentBlockState 中来在 QSyntaxHighlighter 中使用它。
例如:
from PyQt5.Qsci import QsciScintilla
class QsciLexerCustom1(QsciLexerCustom):
def styleText(self, start, end):
editor = self.editor()
SCI = editor.SendScintilla
interline_status = 0
for line in source:
#(tokenizing the line)
for token in tokenized_line:
if token == "string1":
interline_status = 1
if token == "string2":
interline_status = 2
但是,interline_status 将在处理到下一行时重置为 0。我找到了变量QsciScintilla.SCI_GETSTYLEAT,它类似于我想要的如下:
pos = SCI(QsciScintilla.SCI_GETLINEENDPOSITION, index - 1)
interline_state = SCI(QsciScintilla.SCI_GETSTYLEAT, pos)
但是,结果出乎意料。也许我要使用的状态值不在变量的末尾。
QsciScintilla(在 PyQt5 中)中是否存在与 setCurrentBlockState 等效的内容?
【问题讨论】: