1.首先将字体(我选择windows下的宋体simsun.ttf)copy至qte的lib/font目录下
2.设置环境变量export QT_QWS_FONTDIR=/mnt/nfs/qte-arm/lib/fonts/
3.在函数里指定字体
eg:测试例程
1 #include <QtGui/QApplication> 2 #include <QtGui/QWidget> 3 #include <QtGui/QLabel> 4 #include <QtCore/QTextCodec> 5 #include <QtGui/QPushButton> 6 #include <QtGui/QVBoxLayout> 7 #include <QFont> 8 int main(int argc, char* argv[]) 9 { 10 QApplication app(argc, argv); 11 // app.setFont(QFont("simsun"));
12 13 QFont font; 14 font.setPointSize(26); 15 font.setFamily(("simsun")); 16 app.setFont(font); 17 18 QTextCodec::setCodecForTr(QTextCodec::codecForName("utf-8")); 19 QWidget* pWidget = new QWidget; 20 QLabel label(pWidget); 21 // pWidget.showMaximized();
22 pWidget->showMaximized(); 23 label.setText(QObject::tr("北京欢迎您!")); 24 QPushButton* btn = new QPushButton(QObject::tr("close!"), pWidget); 25 QVBoxLayout* layout = new QVBoxLayout; 26 layout->addWidget(&label); 27 layout->addWidget(btn); 28 pWidget->setLayout(layout); 29 QObject::connect(btn, SIGNAL(clicked()), pWidget, SLOT(close())); 30 pWidget->show(); 31 return app.exec(); 32 } 33
|
阅读(9816) | 评论(0) | 转发(0) |