<div dir="ltr"><div dir="ltr"><div>Hi,<br></div>I use this code in Qtextedit to find "sth" but the problem is when I have more data it is lack on speed.<br>"""<br><pre style="background-color:rgb(255,255,255);color:rgb(0,0,0);font-family:"DejaVu Sans Mono";font-size:9.1pt">cursor = <span style="color:rgb(148,85,141)">self</span>.SearchResults.textCursor()<br>format = QtGui.QTextCharFormat()<br>format.setBackground(QtGui.QBrush(QtGui.QColor(<span style="color:rgb(0,128,128);font-weight:bold">"red"</span>)))<br>pp = <span style="color:rgb(148,85,141)">self</span>.m<br>pattern1 = <span style="color:rgb(0,128,128);font-weight:bold">r'\b(?:{})\b'</span>.format(pp)<br>regex = QtCore.QRegExp(pattern1)<br>pos = <span style="color:rgb(0,0,255)">0<br></span>index = regex.indexIn(<span style="color:rgb(148,85,141)">self</span>.SearchResults.toPlainText(), pos)<br>tedad = <span style="color:rgb(0,0,255)">0<br></span><span style="color:rgb(0,0,128);font-weight:bold">while </span>(index != -<span style="color:rgb(0,0,255)">1</span>):<br>    cursor.beginEditBlock()<br>    cursor.setPosition(index)<br>    cursor.movePosition(QtGui.QTextCursor.NextWord, QtGui.QTextCursor.KeepAnchor, <span style="color:rgb(0,0,255)">1</span>)<br>    cursor.endEditBlock()<br>    cursor.mergeCharFormat(format)<br>    pos = index + regex.matchedLength()<br>    index = regex.indexIn(<span style="color:rgb(148,85,141)">self</span>.SearchResults.toPlainText(), pos)<br>"""<br></pre></div></div>