Hi,

I'm puzzled I can't display unicode characters higher than u"\u2094". I can display all below and including u"\u2094" but nothing starting from u"\u2095" and up. How could that be?
e.g.

self.label = QLabel(unichr(int('2094', 16)) + unichr(int('2098', 16)))

Recommended Answers

All 5 Replies

Anyone?
or why can I display u'\u03B7' but not u'\u03C1'?

How can I show Greek letters, for example?

I also noticed, I can show anything in a, say, QLabel with RichText, e.g.

self.lb_test = QLabel(self)
        self.lb_test.setTextFormat(Qt.RichText)
        self.lb_test.setText(u'\u03C1')
        size_policy.setHeightForWidth(self.lb_test.sizePolicy().hasHeightForWidth())
        self.lb_test.setSizePolicy(size_policy)
        self.lb_test.setMinimumSize(self.l_size)

And if I do this:

txt = u'\u03C1'
self.lb_test.setText(txt)

it also shows it. But if I save the unicode string/character in an xml and then read it and put in the label, it shows cr*p, e.g.

***
        self.tree = ElementTree()
        root = Element("root")
        tag = SubElement(root, "test")
        tag.text = u'\u03C1'
        ***
        self.tree = ElementTree(root)
        self.xmlIndent(self.tree.getroot())
        self.tree.write(self.results_file, encoding="utf-8")
        ***

            tree = ElementTree()
            root = tree.parse(file)
            list = root.getiterator()
            for node in list:
                for elem in node:
                    item = elem.getchildren()
                    txt += str(item[0].text) + "<br />"
        ***
        self.lb_test.setText(txt)

Thanks.

My tips are:
You pass byte string to QLalbel with the wrong implicit encoding.
Your font is not able to show the given code point.

Can you give use a working piece of code, that producess the error?
What is the exception that is showing, if any?

Sorry, the code is too big and takes a few files.

I made it work as an HTML unicode rather than pure unicode, e.g.

self.lb_test = QLabel(self)
      self.lb_test.setTextFormat(Qt.RichText)
      self.lb_test.setText("")
      self.lb_test.setSizePolicy(size_policy)
      self.lb_test.setMinimumSize(self.l_size)
      ***
      txt = "&#x3C1;"
      self.lb_test.setText(txt)

In the first post, you want to display the "LATIN SUBSCRIPT SMALL LETTER M" in a normal label. I am sure, that the default font does not contain these. Try setFont...

On linux Qt.QFont( "linux-libertine", 25 ) will display the weird circled plus sign, as expected(?)

The richtext format promotes the problem to another rendering layer, which can fail too:
http://www.fileformat.info/info/unicode/char/2098/browsertest.htm

I had to show a subscript 'm' or some Greek letters. Then I found out Qt can show HTML with CSS formatting in some widgets which works fine... so far

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.