Results 1 to 4 of 4

Thread: add celsius sign end of label

  1. #1
    Join Date
    Jan 2016
    Posts
    7
    Thanks
    1
    Qt products
    Qt5

    Default add celsius sign end of label

    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:

    Qt Code:
    1. ui->label->setText(tempvalue)
    To copy to clipboard, switch view to plain text mode 
    but how can i add "°C" at the end of this?

  2. #2
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    120
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: add celsius sign end of label

    Hello,

    add the UTF character °C at the end, e.g.
    Qt Code:
    1. ui->label->setText(tempvalue+QChar(0x2103));
    To copy to clipboard, switch view to plain text mode 
    assuming tempvalue is the temperature value as QString.

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

  3. #3
    Join Date
    Jan 2016
    Posts
    7
    Thanks
    1
    Qt products
    Qt5

    Default Re: add celsius sign end of label

    thanks, it works.

  4. #4
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: add celsius sign end of label

    Or you can use formatted text output and even add internationalization support:
    Qt Code:
    1. ui->label->setText(tr("%1°C").arg(tempvalue));
    To copy to clipboard, switch view to plain text mode 
    If you use Qt4, make sure CODECFORTR and CODECFORSRC are properly set in the .pro. With Qt5 it is UTF-8 everywhere.

Similar Threads

  1. QRegExp: Last sign has to be a number
    By forenued in forum Qt Programming
    Replies: 6
    Last Post: 21st January 2016, 04:32
  2. how to sign my .msi file
    By athulms in forum Newbie
    Replies: 4
    Last Post: 28th September 2011, 07:10
  3. How to free sign my app ?
    By Sparkle24 in forum Qt for Embedded and Mobile
    Replies: 4
    Last Post: 21st August 2011, 23:25
  4. Euro sign
    By dragon in forum Qt Programming
    Replies: 3
    Last Post: 8th September 2008, 19:58

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.