[PyQt] [PYQT] Increse the regex in QtCore.QRegExp

Maziar Parsijani maziar.parsijani at gmail.com
Wed Oct 3 14:22:54 BST 2018


Hi,
I have found that Qsyntaxhighlighter may be better for huge data.
This is a code which I use but I can not get it to work on qtextedit.
>
> self.SearchResults = QtWidgets.QTextEdit(self)
>> self.SearchResults.setPlainText("The T t myh inH WwtT")
>>
>> brush = QtGui.QBrush(QtCore.Qt.darkBlue, QtCore.Qt.SolidPattern)
>>     keyword = QtGui.QTextCharFormat()
>>     keyword.setForeground(brush)
>>     keyword.setFontWeight(QtGui.QFont.Bold)
>>     listKeywords = "The"
>>     self.highlightingRules = [highlightRule(QtCore.QRegExp("\\b" + key + "\\b"), keyword)
>>                               for key in listKeywords
>>                               ]
>>     for rule in self.highlightingRules:
>>         expression = QtCore.QRegExp(rule.pattern)
>>         index = expression.indexIn(self.SearchResults.toPlainText())
>>
>>         while index >= 0:
>>             length = expression.matchedLength()
>>             self.setFormat(index, length, rule.format)
>>             index = expression.indexIn(self.SearchResults.toPlainText(), index + length)
>>
>>
On Sun, Sep 16, 2018 at 12:17 PM Maziar Parsijani <
maziar.parsijani at gmail.com> wrote:

> Hi Michael,
> I attached an example file on this post,But I summarized the part that I
> want to work on it.I retrieve data from sqlite and set it into textedit and
> here I have just added 2 strings in it.for addition I have to say my data
> is Arabic text.before this I have found a way to compile the exact thing to
> highlight but now the problem is the low speed with more data.
> Thanks for your advice about profiling codes.
>
> On Sun, Sep 16, 2018 at 8:00 AM michael h <michaelkenth at gmail.com> wrote:
>
>> doc.setDefaultStyleSheet(<span class="highlight">found</span>)
>>>
>>> This is where the css rules go, not the html
>>
>>> doc.setHtml()
>>>
>>> this would be where you set the html
>>
>>
>> Aside from that:
>>
>> - Profile the code because the issue may not be where you expect it
>> - You might look into using QSyntaxHighlighter, which would allow you to
>> highlight without inserting HTML markup.
>> - If you could post a self contained runnable example I'd take a closer
>> look
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20181003/0381cc2f/attachment-0001.html>


More information about the PyQt mailing list