[PyQt] [pyqt]how to clear last searched items in my code and how to count my searched item.

Maziar Parsijani maziar.parsijani at gmail.com
Mon Aug 6 12:41:06 BST 2018

I have this code for searching in a Qtextedit.My first problem is that
I can not clear the search result to start a new one.The other thing
I need to know how to count my search results.for example if there are
6 highlighted item I want to count them.

    m = 1
    cur = conn.cursor()
    conn.text_factory = str
    cur.execute(" SELECT text FROM Translation WHERE data = ?", (m,))
    a = 1
    for row in cur:
        self.SearchResults.append('{0} )- {1}'.format(a , str(row[0])))
        #self.text = '{0} )- {1}'.format(a , str(row[0]))
        a = a + 1
def Searchfor(self):

    cursor = self.SearchResults.textCursor()
    format = QtGui.QTextCharFormat()
    pattern = self.lineEdit.text()
    regex = QtCore.QRegExp(pattern)

    pos = 0
    index = regex.indexIn(self.SearchResults.toPlainText(), pos)

    while (index != -1):
        # Select the matched text and apply the desired format
        cursor.movePosition(QtGui.QTextCursor.EndOfWord, 1)
        # Move to the next match
        pos = index + regex.matchedLength()
        index = regex.indexIn(self.SearchResults.toPlainText(), pos)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20180806/0549c36d/attachment.html>

More information about the PyQt mailing list