This commit is contained in:
Charles Haley 2010-04-30 15:24:24 +01:00
parent c79091e71b
commit b5f5a5f5d9

View File

@ -53,16 +53,16 @@ class RegexBuilder(QDialog, Ui_RegexBuilder):
if self.regex_valid(): if self.regex_valid():
text = qstring_to_unicode(self.preview.toPlainText()) text = qstring_to_unicode(self.preview.toPlainText())
regex = qstring_to_unicode(self.regex.text()) regex = qstring_to_unicode(self.regex.text())
cursor = QTextCursor(self.preview.document())
extsel = QTextEdit.ExtraSelection()
extsel.cursor = cursor
extsel.format.setBackground(QBrush(Qt.yellow))
try: try:
for match in re.finditer(regex, text): for match in re.finditer(regex, text):
cursor = QTextCursor(self.preview.document()) es = QTextEdit.ExtraSelection(extsel)
cursor.setPosition(match.start(), QTextCursor.MoveAnchor) es.cursor.setPosition(match.start(), QTextCursor.MoveAnchor)
cursor.setPosition(match.end(), QTextCursor.KeepAnchor) es.cursor.setPosition(match.end(), QTextCursor.KeepAnchor)
sel = QTextEdit.ExtraSelection() selections.append(es)
sel.cursor = cursor
sel.format.setBackground(QBrush(Qt.yellow))
selections.append(sel)
except: except:
pass pass
self.preview.setExtraSelections(selections) self.preview.setExtraSelections(selections)