Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

edited tags
Link
eyllanesc
  • 245.7k
  • 19
  • 205
  • 282
added 3 characters in body
Source Link
musicamante
  • 50k
  • 8
  • 42
  • 77

This snippet can only highlight current line, but it cannot highlight line with soft wraps.

screenshotscreenshot

 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)

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)

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)
Source Link
Jason
  • 40
  • 7

QPlainTextEdit highlight current line with soft wraps?

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)
lang-py

AltStyle によって変換されたページ (->オリジナル) /