<div dir="ltr">I've used QTextDocuments just a little bit in the past, so I'm a bit rusty on this.<br>First question is, why are you using editblocks? As far as I can tell, editblocks are used for "edit" operations, meaning that each edit block is a possible undo/redo operation. In my experience, this consumes a lot of process, as each time you do that a new QUndoCommand will be pushed in the QUndoStack. I had a similar problem for a program of mine which had a function that randomized about 300 parameters: what I didn't realize at the time was that, since each parameter change would push a QUndoCommand, it froze the program for 5-10 seconds. So, I think it's possible that your issue could be related to this.<div>I assume that you wouldn't need that, since you just want to highlight the search results, so maybe you should just use QTextCursor.insertBlock instead.<br></div><div><br></div><div>Also, have you tried to think about another approach? I don't know if the text you show has to be editable or not, but if it doesn't, you could think about using QTextDocument.setHtml and then use a stylesheet.</div><div>It could be something simple as:<br></div><div><br></div><div><font face="monospace, monospace">self.myTextDocument.setDefaultStyleSheet('''</font></div><div><font face="monospace, monospace"> .highlight {</font></div><div><font face="monospace, monospace"> color: red;</font></div><div><font face="monospace, monospace"> }'''</font></div><div><br></div><div>Let's say you the search key is "<font face="monospace, monospace">found</font>", each instance of it will have to be substituted with "<font face="monospace, monospace"><span class="highlight">found</span></font>". After that, simply call setHtml with the contents, and that would be enough.</div><div><br></div><div>Maurizio</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2018-09-15 9:31 GMT+02:00 Maziar Parsijani <span dir="ltr"><<a href="mailto:maziar.parsijani@gmail.com" target="_blank">maziar.parsijani@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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(<wbr>)<br>format = QtGui.QTextCharFormat()<br>format.setBackground(QtGui.<wbr>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>.<wbr>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.<wbr>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>.<wbr>SearchResults.toPlainText(), pos)<br>"""<br></pre></div></div>
<br>______________________________<wbr>_________________<br>
PyQt mailing list <a href="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a><br>
<a href="https://www.riverbankcomputing.com/mailman/listinfo/pyqt" rel="noreferrer" target="_blank">https://www.<wbr>riverbankcomputing.com/<wbr>mailman/listinfo/pyqt</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">È difficile avere una convinzione precisa quando si parla delle ragioni del cuore. - "Sostiene Pereira", Antonio Tabucchi<br><a href="http://www.jidesk.net" target="_blank">http://www.jidesk.net</a></div>
</div>