Reputation: 124
I am using Qtextedit with a search button. here is the code.
format = QTextCharFormat()
format.setBackground(QBrush(QColor("Gray")))
regex = QRegExp(pattern)
if (self.ui_log.checkBox_case.isChecked()==False):
regex.setCaseSensitivity(False)
pos = 0
index = regex.indexIn(self.ui_log.log_textEdit.toPlainText(), pos)
while (index != -1):
cursor.setPosition(index)
cursor.movePosition(QTextCursor.EndOfWord, 1)
cursor.mergeCharFormat(format)
pos = index + regex.matchedLength()
self.ui_log.log_textEdit.moveCursor(??????)
index = regex.indexIn(self.ui_log.log_textEdit.toPlainText(), pos)
Qtextedit have a scrollbar as the input file i am providing in qtextedit is large..
The searched text is high lighted, how can i move to searched text by providing index of word ?
Upvotes: 0
Views: 3321
Reputation: 328594
Instead of moving the existing cursor, set a new one:
self.ui_log.log_textEdit.setTextCursor(cursor);
Upvotes: 3