def highlightBlock(self, text): # Function for formatting if not self.dict: # the text inside this text return # edit field, sets the format formats = QTextCharFormat() # of the text that not match formats.setUnderlineColor(Qt.red) # to the dicts. Red underline. formats.setUnderlineStyle(QTextCharFormat.SpellCheckUnderline) for w in re.finditer(self.words, text): if not self.dict.check(w.group()): self.setFormat(w.start(), w.end() - w.start(), formats)
def mouseOverLabel(self, e): if self.previousKeywordFormat['cursor']: return cursor = self.cursorForPosition(e.pos()) cursor.select(QTextCursor.WordUnderCursor) newFormat = QTextCharFormat() newFormat.setUnderlineColor(QColor("#007ACC")) newFormat.setFontItalic(True) newFormat.setUnderlineStyle(QTextCharFormat.SingleUnderline) cursor.setCharFormat(newFormat) formater = Formater() self.previousKeywordFormat['cursor'] = cursor if isinstance(self.file, AssemblyFileProxy): self.previousKeywordFormat['format'] = formater._formatiraj( 255, 255, 255) else: self.previousKeywordFormat['format'] = formater.stilovi[ 'declarations']
class ParagonScriptHighlighter(QSyntaxHighlighter): def __init__(self, document): super().__init__(document) self.error_line = None self.command_format = QTextCharFormat() self.command_format.setForeground(QtCore.Qt.darkMagenta) self.error_format = QTextCharFormat() self.error_format.setUnderlineColor(QtCore.Qt.darkRed) self.error_format.setUnderlineStyle( QtGui.QTextCharFormat.SpellCheckUnderline) self.error_format.setBackground(QtCore.Qt.red) def highlightBlock(self, text: str): if text.startswith("$") and not text.startswith( "$G") and not text.startswith("$Nu"): self.setFormat(0, len(text), self.command_format) if self.currentBlock().blockNumber() == self.error_line: self.setFormat(0, len(text), self.error_format)