Search code examples
qt4qtexteditqplaintextedit

Vertical alignment of characters in a QTextEdid (or QPlainTextEdit)


I'm trying to write the following nice table in a QTextEdit/QPlainTextEdit:

 +-----+-----+---------+------+---+---Pi 2---+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+

But when I do appendPlainText(QString) I don't get characters aligned vertically. It seems each character has a different width so the result is almost a mess, with text kind of left aligned.


Solution

  • Check that the font used to display the text in the widget is a Monospaced font. If necessary, change the font to for example 'Courier New' using QWidget::setFont()