[PyQt] [PYQT]Search in QTextedit
Maziar Parsijani
maziar.parsijani at gmail.com
Sun Aug 19 17:01:13 BST 2018
Hi
I use the below code to search in qtextedit to match a word.Are there any
better Idea.
> cursor = self.SearchResults.textCursor()
>>>> format = QtGui.QTextCharFormat()
>>>> format.setForeground(QtGui.QBrush(QtGui.QColor("red")))
>>>> self.lineEdit.backspace()
>>>> pattern = self.lineEdit.text()
>>>> regex = QtCore.QRegExp(pattern)
>>>> pos = 0
>>>> index = regex.indexIn(self.SearchResults.toPlainText(), pos)
>>>> #Tedad = 0
>>>> while (index != -1):
>>>> cursor.setPosition(index)
>>>>
>>>> cursor.movePosition(QtGui.QTextCursor.WordLeft,QtGui.QTextCursor.KeepAnchor)
>>>> cursor.mergeCharFormat(format)
>>>> pos = index + regex.matchedLength()
>>>> index = regex.indexIn(self.SearchResults.toPlainText(), pos)
>>>>
>>> For example I need it to detect white spaces(" ")and match them too.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20180819/97567361/attachment.html>
More information about the PyQt
mailing list