./configure -qt-freetype ...
配置好后,make,make install 就可以生成QT库,
- #include <QtGui>
- #include "macmainwindow.h"
- #include <QDebug>
- #include <QFontDatabase>
- #include <QTextCodec>
- #include <QPainter>
- #include <QWSServer>
- #if 0
- int main(int argc, char **argv)
- {
- QApplication app(argc, argv);
- MacMainWindow mainWindow;
- mainWindow.show();
- return app.exec();
- }
- #else
- int main(int argc, char **argv)
- {
- QWSServer::setBackground(QColor(0,0,0,0));
- QWSServer::setCursorVisible(false);
- QFontDatabase database;
- foreach (const QString &family, database.families(QFontDatabase::SimplifiedChinese))
- {
- qDebug()<<family;
- }
- QTextCodec::setCodecForTr(QTextCodec::codecForName("GBK"));
- QTextCodec::setCodecForCStrings(QTextCodec::codecForName("GBK"));
- QTextCodec::setCodecForCStrings(QTextCodec::codecForName("GBK"));
- QPalette pa;
- pa.setColor(QPalette::WindowText,Qt::red);
- QApplication app(argc, argv);
- QString chinese;
- QLabel label ,label1;
- QFont font("Source Han Sans CN",20,QFont::Bold);
- label.setGeometry(200,80,900,200);
- label.setFont(font);
- chinese = QString::fromUtf8("思源字体\r\nQT中文字体显示不同大小任意设置:20号加粗字体");
- label.setText(chinese);
- label.setPalette(pa);
- label.show();
- QFont font1("Source Han Sans CN",30,QFont::Normal);
- label1.setGeometry(200,280,900,200);
- label1.setFont(font1);
- chinese = QString::fromUtf8("思源字体\r\nQT中文字体显示不同大小任意设置:30号正常字体");
- label1.setText(chinese);
- label1.setPalette(pa);
- label1.show();
- return app.exec();
- }
- #endif
有可能这样子仍显示乱码,这个是由于你的C文件编码格式有关系,可以使用Notepad++修改C文件编码格式,使用UFT-8无BOM模式。保存后编译没有问题。
联系客服