PDA

View Full Version : add celsius sign end of label



rapid84
19th January 2016, 17:06
Hi,
I am using a label for showing temperature value, and i want to add celcius sign to this label like this: "27°C". I am using this code:


ui->label->setText(tempvalue) but how can i add "°C" at the end of this?

ars
19th January 2016, 19:00
Hello,

add the UTF character °C at the end, e.g.
ui->label->setText(tempvalue+QChar(0x2103)); assuming tempvalue is the temperature value as QString.

See http://www.fileformat.info/info/unicode/char/2103/index.htm
Best regards
ars

rapid84
19th January 2016, 19:48
thanks, it works.

yeye_olive
20th January 2016, 09:17
Or you can use formatted text output and even add internationalization support:

ui->label->setText(tr("%1°C").arg(tempvalue));
If you use Qt4, make sure CODECFORTR and CODECFORSRC are properly set in the .pro. With Qt5 it is UTF-8 everywhere.