Search code examples
qtunicodeqgraphicsitemqgraphicstextitem

How can I display unicode in QGraphicsTextItem?


I would like to be able to display Unicode in QGraphicsTextItem (or a subclass of it).

The only way to set text in QGraphicsTextItem seems to be

setPlainText(text);

Trying

setPlainText(QString::fromUtf8("Caf\x00e9 Frap\x00e9"));

or

QTextCodec::setCodecForCStrings(QTextCodec::codecForName("utf8"));
setPlainText("Café Frapé");

QTextCodec::setCodecForCStrings(QTextCodec::codecForName("utf8"));
setPlainText("Caf\x00e9 Frap\x00e9");

I get:

Caf? Frap?

It seems that no matter what I do (which I am not sure is correct) I do not get the output right...

Do QGraphicsTextItem support unicode ? Is maybe the setPlainText function at fault - but then what are the alternatives ? (I looked into setDocument but it also sets plain text...)

Edit - copying the special characters inside the QGraphicsTextItem works, once on screen, but still unable to place any unicode from code.


Solution

  • I think you should use the

    QGraphicsTextItem item.
    item.setHtml( "Café Frapé" );
    

    function instead of the mentioned. Read this QGraphicsTextItem::setHtml.