QT 4.7 Support Chinese (QT4.7) (Chinese) (MAKEQPF)

Source: Internet
Author: User

QT 4.7 Support Chinese (QT4.7) (Chinese) (MAKEQPF)

Summary:

QT4.7.0 when porting to the Development Board, Chinese support is essential, how to let QT support Chinese, how to make Qt supported font files, how to make the Qt UI editor in the font size and the size of the development Board consistent. The author carried out one by one verification through experiments.

Introduced:

1. First Experience:

QT program in the font and size indicated in the/fonts directory does not have a corresponding library file, QT will select an existing font file to display, then, if your system only need a font and font size, then you can delete the fonts directory is not required to all the fonts files, Just keep the font file that you need.

The above is a convenient way, regardless of the font and size set in the program, it will always be in the fonts directory of this unique font file format to display. However, many times, we need a variety of fonts and font size coexist, then the following will explain how to add Wenquanyi 12 13 15 164 font size of bold and a total of 8 font files, and then through the Qfont to set them, access to the corresponding font file.

First, download the Font_wenquanyi font, the font has TTF, BDF, QPF and other formats, we download here is the QPF format, if it is other format, you need to convert.

Then copy the downloaded font file to the/usr/local/trolltech/qtembedded-4.7.0-arm/lib/fonts directory of the Development Board, such as:

Take Wenquanyi_150_50 as an example: Wenquanyi is a font, 150 is a 15th font, 50 is a thin body, and 75 is bold.

The program in QT is as follows:

#include <QtGui/QApplication>
#include <QTextCodec>
#include "hmi_desktop.h"
intmain(int argc, char*argv[])
{
    QApplication a(argc, argv);
    //中文支持
    QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
    QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));        //支持Tr中文
    QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); //支持中文文件名显示
    QFont font;
    font.setPointSize(160); //实际上是16的字号,但设成16却不行
    font.setFamily(("wenquanyi"));
    font.setBold(false);
    a.setFont(font);
    //--
    Hmi_desktop w;
    w.show();
    returna.exec();
}

Run on the Development Board, how about the font is not changed. Happy, Proud!

Well, don't be proud to forget the shape, in fact this is just a beginning. Imagine, if you want to display 32 or 48 font size, or you want to display other fonts, and the Internet can not download, how to do?

2, to point the real gun solid material

The following describes how to make a QPF file.

QT has a tool: MAKEQPF, is specifically used to convert QPF files, but this program can only run in the embedded environment, so need to compile X86 version of QT4.7.

Unzip the qt-everywhere-opensource-src-4.7.0.tar.gz, and copy it two copies, named: QT-4.7.0-X86,QT-4.7.0-PC (compiled x86 is to get MAKEQPF, Compiling the PC is to get Qvfb,arm version of the previous compilation, this is not necessary)

cd qt-4.7.0-x86
./configure -prefix /usr/local/Trolltech/qt-4.7.0-x86 -opensource -confirm-license -embedded x86 -qt-gfx-qvfb -qt-kbd-qvfb -qt-mouse-qvfb -make tools
make
make install
cd qt-4.7.0-pc
./configure -prefix /usr/local/Trolltech/qt-4.7.0-pc -opensource -confirm-license
make
make install
#接下来安装PC版本的qvfp
cd qt-4.7.0-pc
cd tools/qvfp
make
cp qt-4.7.0-pc/bin/qvfp /usr/local/Trolltech/qt-4.7.0-x86/bin

After the installation is complete, you can find them in the directory below.

cd /usr/local/Trolltech/qt-4.7.0-x86/bin/

Prepare the font file to be converted, find it under C:\WINDOWS\Fonts, or download it.

Here we are downloading the Wqy-zenhei.ttf.

Copy the Wqy-zenhei.ttf font file to/usr/local/trolltech/qt-4.7.0-x86/lib/fonts so that it is found in MAKEQPF

Start Qvfb, and run MAKEQPF software in QVFB

./qvfb -width 800 -height 480 &
./makeqpf -qws

  

Output 16, 24, 32 and other font size, so that in the output path specified in the directory can see these files (Note: If you choose the root directory, you do not see the file, to be seen in the terminal)

Why is QPF2, meticulous friend may see out, this must explain, QPF is qt2 and Qt3 use, later Qt4 changed to QPF2, and we can see, the size of 16, is directly 16, is no longer 160, the following to see the use of it, and above or there is a little difference.

or set it as above, assuming I want to display the font number 24th:

Qfont font;

Font.setpointsize (160); Here is set to 24, set to find very small, only when set to 80, only 24 of the size, after looking at the help document, found that the original setpixelsize is set font size, changed to Font.setpixelsize (24); You can do it. (Pointsize is a relative value, DPI-related; Generally, the DPI value on Windows is 96, while the DPI value of embedded Linux is typically 72, so the font size is much smaller.) So should use Qfont::setpixelsize).

Font.setfamily (("Wenquanyi"));//This family how to set, is the file name, not, to see here

Font.setfamily ("

Wenquanyi Zen Hei "));

If you have a space, don't lose it.

The other settings are the same,

Run a bit, the word is not getting bigger.

3, solve the problem of setpointsize word is too small

In the UI editor, there is no setpixelsize setting, only setpointsize. If you want to display the normal font size on the board, you must set the pointsize to large, so that the word on the computer becomes oversized, and you cannot achieve the WYSIWYG effect through the UI editor. As we said earlier, this is due to the different dpi of the monitor. In QT applications, the DPI can be set by environment variables, as follows:

Export qws_display= "linuxfb:mmwidth95:0" Export qws_size= "640x480"

Restarting the QT application, found that the font size and the size of the computer is not so large, the value of 95 is not very accurate, need to follow the monitor to adjust, enter the appropriate DPI value, (I use the Group Chong At056tn53 screen, the DPI value is set to 180 more appropriate)

4. Further attempts

Qt directly supports TTF font files, we directly copy several TTF files to/usr/local/trolltech/qtembedded-4.7.0-arm/lib/fonts directory, delete qpf files

Re-run on the Development Board, found that several fonts and font size can support, it appears that the system has a variety of font size, with TTF file is quite convenient.

Conclusion:

Some people say that TTF file is very large, the comparison fee FLASH,QPF is a bitmap font file, the use of flash smaller, and access faster than TTF. At present, through the visual temporary resolution is not fast, but TTF files only about 10M, the converted QPF file added up a total of bedrooms trillion. More than the TTF fee Flash, I do not know whether it is the cause of the setup.

Resources:

How to build Qt4.7.0 embedded development environment HTTP://BLOG.163.COM/ALLEGRO_TYC/BLOG/STATIC/33743768201101311239471/

The production of QPF font in QT and the realization of the rotated fonts http://www.360doc.com/content/10/0308/00/79031_17944837.shtml

Qt Font Size calculation http://losemyheaven.blog.163.com/blog/static/17071980920111283934557/

QT 4.7 Support Chinese (QT4.7) (Chinese) (MAKEQPF)

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.