Results 1 to 5 of 5

Thread: Getting superscript of arbitrary number to use in a QString

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2013
    Posts
    13
    Thanks
    4

    Default Re: Getting superscript of arbitrary number to use in a QString

    Thanks. I wrote a small function myself then, that returns a QString with the superscripts 0-9. Though this is in the code -does qt have a way of converting any of the representations found here to the corresponding character?
    -> http://www.fileformat.info/info/unic...2075/index.htm

    Anyhow, Arial seems to render them all fine for now.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Getting superscript of arbitrary number to use in a QString

    Yes. Qt can convert from several of those encodings...
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char **argv)
    4. {
    5. QApplication app(argc, argv);
    6.  
    7. // UTF-8
    8. const char s[] = {
    9. 0x78, // Lower case X
    10. 0xE2, 0x81, 0xB0, // superscript zero
    11. 0xC2, 0xB9, // superscript one
    12. 0xC2, 0xB2, // superscript two
    13. 0xE2, 0x82, 0x83, // subscript three
    14. 0xE2, 0x82, 0x84, // subscript four
    15. 0x00 // NUL terminator
    16. };
    17. QString str = QString::fromUtf8(s);
    18.  
    19. // UTF-16, BOM then same characters as above
    20. const ushort s16[] = {
    21. 0xFEFF, // byte order mark
    22. 0x0078,
    23. 0x2070,
    24. 0x00B9,
    25. 0x00B2,
    26. 0x2083,
    27. 0x2084,
    28. 0x0
    29. };
    30. QString str16 = QString::fromUtf16(s16);
    31.  
    32. // str == str16 is true
    33.  
    34. QFont font("Arial", 36);
    35. QLabel l(str16);
    36. l.setFont(font);
    37. l.show();
    38.  
    39. return app.exec();
    40. }
    To copy to clipboard, switch view to plain text mode 

    You will probably see that the rendering of the superscript 1, 2 and 3 (U+00Bx) are different from 0 and 4-9 (U+207x).
    Last edited by ChrisW67; 13th May 2013 at 23:57.

Similar Threads

  1. Replies: 5
    Last Post: 2nd November 2012, 03:38
  2. Strange QString::number behaviour
    By sastrian in forum Qt Programming
    Replies: 1
    Last Post: 7th September 2012, 08:29
  3. Replies: 16
    Last Post: 21st May 2011, 12:22
  4. Can I use arbitrary constants in a connect()?
    By WinchellChung in forum Newbie
    Replies: 3
    Last Post: 18th February 2008, 22:48
  5. strange problem about QString::number(double)
    By yuzr in forum Qt for Embedded and Mobile
    Replies: 4
    Last Post: 24th December 2007, 13:05

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
  •  
Qt is a trademark of The Qt Company.