BSP is linux L3.14.28_1.0.0-ga -〈yocto〉
QT5.3.2 support UI Chinese font. The default is English, and now need in QT UI to display Chinese characters, how to add fonts. Please help
#include "meihuantest.h"
#include <QApplication>
#include <QTextCodec>
#include <QTextEncoder>
#include <QtCore/qglobal.h>
#include <QDebug>
#include <iostream>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
QFont font;
font.setFamily(QString::fromUtf8("WeiQuanYi Zen Hei"));
font.setPointSize(12);
a.setFont(font);
meihuantest w;
w.show();
return a.exec();
}
#include "meihuantest.h"
#include "ui_meihuantest.h"
#include <QApplication>
#include <QTextCodec>
#include <QTextEncoder>
#include <QtCore/qglobal.h>
#include <QDebug>
#include <iostream>
#include <QFontDatabase>
meihuantest::meihuantest(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::meihuantest)
{
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
QFont font;
font.setFamily(QString::fromUtf8("WeiQuanYi Zen Hei"));
font.setPointSize(12);
this->setFont(font);
ui->setupUi(this);
QFontDatabase database;
foreach (const QString &family,database.families())
{
qDebug()<<family;
ui->textEdit->append(family);
ui->label->setText(QObject::trUtf8("A祖国"));
ui->lineEdit->setText(QString::fromLocal8Bit("B我爱你我的祖国"));
ui->lineEdit->setText(QObject::trUtf8("C我爱你我的"));
ui->lineEdit->setText(QString::fromLatin1("D中文"));
}
resize(800,600);
}
meihuantest::~meihuantest()
{
delete ui;
}
root@imx6qsabresd:/usr/lib/fonts# ls
DejaVuSans-Bold.ttf c0582bt_.pfb helvetica_180_50i.qpf
DejaVuSans-BoldOblique.ttf c0583bt_.pfb helvetica_180_75.qpf
DejaVuSans-Oblique.ttf c0611bt_.pfb helvetica_180_75i.qpf
DejaVuSans.ttf c0632bt_.pfb helvetica_240_50.qpf
DejaVuSansMono-Bold.ttf c0633bt_.pfb helvetica_240_50i.qpf
DejaVuSansMono-BoldOblique.ttf c0648bt_.pfb helvetica_240_75.qpf
DejaVuSansMono-Oblique.ttf c0649bt_.pfb helvetica_240_75i.qpf
DejaVuSansMono.ttf cour.pfa helvetica_80_50.qpf
DejaVuSerif-Bold.ttf courb.pfa helvetica_80_50i.qpf
DejaVuSerif-BoldOblique.ttf courbi.pfa helvetica_80_75.qpf
DejaVuSerif-Oblique.ttf couri.pfa helvetica_80_75i.qpf
DejaVuSerif.ttf cursor.pfa japanese_230_50.qpf
README dejavu_sans_11_50.qpf2 l047013t.pfa
UTBI____.pfa fixed_120_50.qpf l047016t.pfa
UTB_____.pfa fixed_70_50.qpf l047033t.pfa
UTI_____.pfa helvetica_100_50.qpf l047036t.pfa
UTRG____.pfa helvetica_100_50i.qpf l048013t.pfa
Vera.ttf helvetica_100_75.qpf l048016t.pfa
VeraBI.ttf helvetica_100_75i.qpf l048033t.pfa
VeraBd.ttf helvetica_120_50.qpf l048036t.pfa
VeraIt.ttf helvetica_120_50i.qpf l049013t.pfa
VeraMoBI.ttf helvetica_120_75.qpf l049016t.pfa
VeraMoBd.ttf helvetica_120_75i.qpf l049033t.pfa
VeraMoIt.ttf helvetica_140_50.qpf l049036t.pfa
VeraMono.ttf helvetica_140_50i.qpf micro_40_50.qpf
VeraSe.ttf helvetica_140_75.qpf unifont_160_50.qpf
VeraSeBd.ttf helvetica_140_75i.qpf wqy-microhei.ttc
c0419bt_.pfb helvetica_180_50.qpf wqy-zenhei.ttc
root@imx6qsabresd:/usr/lib/fonts#
WenQuanYi Zhe Hei
WenQuanYi Zhe Hei Mono
WenQuanYi Zhe Hei Sharp
WenQuanYi Micro Hei
WenQuanYi Micro Hei Mono
Please help
No display
Solved! Go to Solution.
Hi haibo,
Here you need to download the Chinese fonts first and put it into the directory /usr/lib/fonts on your board. Then set the font you need in the main.cpp of QT.
You also can set the font type you like. Take " SimSun" as an example:
QApplication a(argc, argv); | |
QFont font; | |
font.setPixelSize(20); | |
font.setFamily("SimSun"); | |
QApplication::setFont(font); | |
... |
Hope this can help you.
Have a great day,
Dan
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi haibo,
Here you need to download the Chinese fonts first and put it into the directory /usr/lib/fonts on your board. Then set the font you need in the main.cpp of QT.
You also can set the font type you like. Take " SimSun" as an example:
QApplication a(argc, argv); | |
QFont font; | |
font.setPixelSize(20); | |
font.setFamily("SimSun"); | |
QApplication::setFont(font); | |
... |
Hope this can help you.
Have a great day,
Dan
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------