79834360

Date: 2025-12-01 05:19:16
Score: 1
Natty:
Report link

QPlainTextEdit does not support CSS/HTML line-height because it uses a low-level

QTextDocument + layout engine. So changing <p> styles or using setHtml() has no

effect on QPlainTextEdit.

To change the line spacing, you must modify the QTextBlockFormat of the

document, not the widget:

cursor = self.textCursor()

block = cursor.block()

fmt = block.blockFormat()

fmt.setLineHeight(150, QTextBlockFormat.ProportionalHeight)

cursor.setBlockFormat(fmt)

This applies a proportional line-height (e.g., 150% = 1.5x spacing) to each block.

If you want to apply it to all lines, you can loop through all blocks in the

document and apply the same format.

QPlainTextEdit simply does not support CSS line-height, so adjusting the

QTextBlockFormat is the correct Qt-based solution.

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (1):
Posted by: Osan Paudel