0

I want to write a text in QTextBrowser in PyQt. I have something like this:

    for line in working_data:
        word = line.split(";")
        self.ui.textBrowser.append("{:30}{:>30}".format(word[1], word[2]))

With this I get something like (left and right alignment):

ID      Value
123      10,00
1234      20,00
1      330,00
12345      1,00

I would like to have it like this:

ID       Value
123      10,00
1234     20,00
1       330,00
12345     1,00

How to achieve that? I looked here and tried {:30}'.format('test') and {:>30}'.format('test') for right align case, but it would'n reserve 30 places for a first word.

Hrvoje T
  • 3,365
  • 4
  • 28
  • 41
  • 1
    What is the font you use in the text browser? You have to use a mono-spaced font, like as courier, to ensure that all characters have the same width. – titusjan Mar 03 '17 at 07:15
  • Thank you! The line `self.ui.textBrowser.setFontFamily("monospace")` did it. – Hrvoje T Mar 03 '17 at 10:20

0 Answers0