PDA

View Full Version : Adding greek text to a QLabel by code



Momergil
19th May 2014, 21:25
Hello!

I want to display text characters in a QLabel, something like this:



ui->label->setText("Φ");


I'm not very familiar with special characters in Qt; every time till now I've being using ASCII hexa characters to set special chars, but now it would seem I'll have to use UTF-8. The problem is that I'm really not familiar with text codes and encodings and the like (something that is in my TOLEARN list of Qt) and I need this quickly :)

Doing some research, I found this thread: http://www.qtcentre.org/threads/8108-greek-symbols (and also http://www.qtcentre.org/threads/3467-unable-to-have-greek-characters-appear-in-a-text-Label), but nothing of the provided methods worked for me :(

I'ld also like to add that it should be "quick insertions" of special characters (greek text), so I'ld like to avoid whole-code changes such as by using method as QTextCodec::setCodecForCStrings() or anything of the like that has a more "global scope".


Thanks for any help,

Momergil


Details: using Qt 4.8 and Linux

Momergil
30th June 2014, 19:13
No one have a clue about this? :(

anda_skoa
30th June 2014, 19:16
Well, the easiest way is to have the source file in UTF-8 encoding and use QString::fromUtf8().


Cheers,
_