Search code examples
pythonqtpyqt5qtextbrowser

Python - pyqt5 - Alignment of text goes wrong in qtextbrowser when working with a specific font


I have a string array which contains strings of a specific font (සිංහල). When I append those strings to a qtextbroswer, alignment goes wrong as

[this output screenshot.]

I think the caused character for this issue is 'නු'. Because it has higher height than other characters.

Following is the code segment I have used for this.

self.chars = ['වචන', 'වචනා', 'වචනි','වචනී','වචන', 'වචනු', 'වචනූ', 'වචනෙ', 'වචනේ']
self.textBrowser.append(' '.join(x for x in self.chars))

How can I get rid of this issue?

UPDATE:

I uploaded the project here.

steps to run:

  • run test2.py
  • click 'select an image'
  • select any image
  • click 'upload and test'

Now you will see the output.


Solution

  • I fixed the issue by myself. Instead of set font inside a method, I inserted following code into UI itself (using qt designer).

    font = QtGui.QFont()
    font.setFamily("Iskoola Pota")
    font.setPointSize(20)
    self.textBrowser.setFont(font)