Here is code I use:
word = self.lineEdit.text()
extraSelections = []
while(self.
plainTextEdit.
find(word,QtGui.
QTextDocument.
FindWholeWords)): '''
selection = QtWidgets.QTextEdit.ExtraSelection()
selection.format.setProperty(QtGui.QTextFormat.FullWidthSelection, True)
selection.cursor = self.plainTextEdit.textCursor()
selection.cursor.clearSelection()
extraSelections.append(selection)
'''
cursor = self.plainTextEdit.textCursor()
currentWord
= QtWidgets.
QTextEdit.
ExtraSelection() Color
= QtGui.
QColor(191,
191,
191,
189) currentWord.format.setBackground(Color)
currentWord.cursor = cursor
extraSelections.append(currentWord)
self.plainTextEdit.setExtraSelections(extraSelections)
self.plainTextEdit.setFocus()
word = self.lineEdit.text()
extraSelections = []
self.plainTextEdit.moveCursor(QtGui.QTextCursor.Start)
while(self.plainTextEdit.find(word,QtGui.QTextDocument.FindWholeWords)):
'''
selection = QtWidgets.QTextEdit.ExtraSelection()
selection.format.setProperty(QtGui.QTextFormat.FullWidthSelection, True)
selection.cursor = self.plainTextEdit.textCursor()
selection.cursor.clearSelection()
extraSelections.append(selection)
'''
cursor = self.plainTextEdit.textCursor()
cursor.select(QtGui.QTextCursor.WordUnderCursor)
currentWord = QtWidgets.QTextEdit.ExtraSelection()
Color = QtGui.QColor(191, 191, 191, 189)
currentWord.format.setBackground(Color)
currentWord.cursor = cursor
extraSelections.append(currentWord)
self.plainTextEdit.setExtraSelections(extraSelections)
self.plainTextEdit.setFocus()
To copy to clipboard, switch view to plain text mode
What am I doing wrong?
Bookmarks