Qte4 supports Chinese Fonts

Source: Internet
Author: User

Qte4 supports Chinese Fonts

Qt version: qte-4.6.2 Development Board: fl2440 Compiler: arm-unknown-linux-gnueabi-gcc-4.4.6 do not know the Chinese font QT interface, the font is displayed as a square or no content. Next we will solve this problem. 1. Download The wenquanyi font suffixed with qpf and copy wenquanyi_120_50.qpf and wenquanyi_120_70.qpf to $ qtdir/lib/fonts in the file system. Note: 120 is the 12-digit font, and 70 is bold compared with 50. Select the font number based on the LCD size of the Development Board. The size of the downloaded font is 12, 13, 15, or 16. 2. This step is related to programming. This is my example:
  1. # Include "mainwindow. H"
  2. # Include <qtextcodec>
  3. Int main (INT argc, char
    * Argv [])
  4. {
  5. Qapplication app (argc, argv );
  6. Qtextcodec: setcodecforlocale (qtextcodec: codecforname ("UTF-8 "));
  7. Qtextcodec: setcodecfortr (qtextcodec: codecforname ("UTF-8 "));
    // Supports tr Chinese
  8. Qtextcodec: setcodecforcstrings (qtextcodec: codecforname ("UTF-8 "));
    // Supports display of Chinese file names
  9. Qfont font;
  10. Font. setpointsize (12 );
    // Font size of 12
  11. Font. setfamily ("wenquanyi "));
  12. Font. setbold (false );
  13. App. setfont (font );
  14. Mainwindow window;
  15. Window. Show ();
  16. Bool OK = app.exe C ();
  17. ////////......
  18. Return OK;
  19. }

The key is the # include <qtextcodec> header file.

In this way, the program can support Chinese characters. For TTF fonts, you can use the makeqpf program of QT to convert them into qpf fonts.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.