This snippet can only highlight current line, but it cannot highlight line with soft wraps.
screenshot
def highlightCurrentLine(self):
extraSelections = []
if not self.isReadOnly() and self.toPlainText(): # and self.toPlainText()
selection = QTextEdit.ExtraSelection()
lineColor = QColor(Qt.yellow).lighter(160)
selection.format.setBackground(lineColor)
selection.format.setProperty(QTextFormat.FullWidthSelection, True)
selection.cursor = self.textCursor()
selection.cursor.clearSelection()
extraSelections.append(selection)
self.setExtraSelections(extraSelections)
eyllanesc
246k19 gold badges205 silver badges282 bronze badges
lang-py
QTextEdit.ExtraSelection()instead ofextraSelections()? Also, please provide a minimal reproducible example.QTextEdit.ExtraSelection()will exit with -1073740791 (0xC0000409)