A
akshay.ksth
I am using the following Highlighter class for Spell Checking to work on myQTextEdit.
class Highlighter(QSyntaxHighlighter):
pattern = ur'\w+'
def __init__(self, *args):
QSyntaxHighlighter.__init__(self, *args)
self.dict = None
def setDict(self, dict):
self.dict = dict
def highlightBlock(self, text):
if not self.dict:
return
text = unicode(text)
format = QTextCharFormat()
format.setUnderlineColor(Qt.red)
format.setUnderlineStyle(QTextCharFormat.SpellCheckUnderline)
unicode_pattern=re.compile(self.pattern,re.UNICODE|re.LOCALE)
for word_object in unicode_pattern.finditer(text):
if not self.dict.spell(word_object.group()):
print word_object.group()
self.setFormat(word_object.start(), word_object.end() - word_object.start(), format)
But whenever I pass unicode values into my QTextEdit the re.finditer() doesnot seem to collect it.
When I pass "I am a नेपाली"into the QTextEdit. The output is like this:
I I I a I am I am I am a I am a I am a I am a I am a I am a I am a I ama
It is completely ignoring the unicode. What might be the issue. I am new toPyQt and regex. Im using Python 2.7 and PyQt4.
class Highlighter(QSyntaxHighlighter):
pattern = ur'\w+'
def __init__(self, *args):
QSyntaxHighlighter.__init__(self, *args)
self.dict = None
def setDict(self, dict):
self.dict = dict
def highlightBlock(self, text):
if not self.dict:
return
text = unicode(text)
format = QTextCharFormat()
format.setUnderlineColor(Qt.red)
format.setUnderlineStyle(QTextCharFormat.SpellCheckUnderline)
unicode_pattern=re.compile(self.pattern,re.UNICODE|re.LOCALE)
for word_object in unicode_pattern.finditer(text):
if not self.dict.spell(word_object.group()):
print word_object.group()
self.setFormat(word_object.start(), word_object.end() - word_object.start(), format)
But whenever I pass unicode values into my QTextEdit the re.finditer() doesnot seem to collect it.
When I pass "I am a नेपाली"into the QTextEdit. The output is like this:
I I I a I am I am I am a I am a I am a I am a I am a I am a I am a I ama
It is completely ignoring the unicode. What might be the issue. I am new toPyQt and regex. Im using Python 2.7 and PyQt4.