1

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
asked Dec 9, 2021 at 5:01
3
  • Why are you using QTextEdit.ExtraSelection() instead of extraSelections()? Also, please provide a minimal reproducible example. Commented Dec 9, 2021 at 5:19
  • @musicamante I just reuse other people's code. QTextEdit.ExtraSelection() will exit with -1073740791 (0xC0000409) Commented Dec 9, 2021 at 7:06
  • Then those people are wrong, or you didn't use their code properly. We still need a proper MRE, though. Commented Dec 9, 2021 at 8:15

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.