[PyKDE] how to highlight a part of text in multiline document.

Keo Sophon keosophon at khmeros.info
Wed Sep 13 11:08:39 BST 2006


Dear all,

I have a code as following:

----------------------------------------
class operator():
	...........
	self.highlight = HighLight(docPointer, self._offset, self._matchlength)
	.........
       
class HighLight(QtGui.QSyntaxHighlighter):
   
    def __init__(self, doc, offset, matchlength):    
        QtGui.QSyntaxHighlighter.__init__(self, doc)             
        self.offset = offset
        self.matchlength = matchlength                                

    def highlightBlock(self, doc):                       
        self.format = QtGui.QTextCharFormat ()
        self.format.setFontWeight(QtGui.QFont.Bold)
        self.format.setForeground(QtCore.Qt.darkMagenta)                
        self.setFormat(self.offset, self.matchlength, self.format)

--------------------------------------------

when i enter a word into a textbox, it will look for the word in another 
textbox, if the word is found, the highlight will be marked on that word. 
However, It highlighted correctly only on the one line text document, It will 
be wrong with multiline document.

Is anything wrong in the code? Could you correct it?

Thanks,
Phon




More information about the PyQt mailing list