Qt 字体
1. Qt
#include <QFontDatabase>QString loadFontFromFile(QString path){static QString font;static bool loaded = false;if(!loaded){loaded = true;int loadedFontID = QFontDatabase::addApplicationFont(path);QStringList loadedFontFamilies = QFontDatabase::applicationFontFamilies(loadedFontID);if(!loadedFontFamilies.empty())font = loadedFontFamilies.at(0);}return font;}QString fontName = loadFontFromFile(":/font/font2.TTC");QFont font(fontName);......QApplication::setFont(font);
2. pyqt
def main():'''main'''from PyQt4.QtGui import QApplicationapp = QApplication(sys.argv)'''设置微软雅黑字体'''loadedFontID = QFontDatabase.addApplicationFont("./msyh.ttf")loadedFontFamilies = QFontDatabase.applicationFontFamilies(loadedFontID)if(list(loadedFontFamilies).__len__()>0):fontName = loadedFontFamilies[0]font = QFont(fontName)app.setFont(font)win = MainWindow()win.showFullScreen()app.exec_()if __name__ == '__main__':main()
3. ubuntu 文泉驿字体
3.1 安装字体
sudo apt-get install ttf-wqy-zenhei
3.2 查看字体命令
fc-list
3.3 使用字体
'''设置字体,文泉雅黑'''#font= QFont("Sans")font= QFont("WenQuanYi Micro Hei")QApplication.setFont(font)