目录
- #include
- #include
- #include
- #include
- #include
-
- int main(int argc, char *argv[]) {
- QApplication app(argc, argv);
-
- // 加载字体文件
- int fontId = QFontDatabase::addApplicationFont(":/path/to/hyyj.ttf");
- if (fontId == -1) {
- qWarning() << "Failed to load font!";
- return -1;
- }
-
- // 获取字体系列名称
- QStringList fontFamilies = QFontDatabase::applicationFontFamilies(fontId);
- if (fontFamilies.isEmpty()) {
- qWarning() << "Failed to retrieve font families!";
- return -1;
- }
-
- QString fontFamily = fontFamilies.at(0);
-
- // 创建并设置 QLabel
- QLabel label("Hello, Qt with custom font!");
- QFont customFont(fontFamily);
- label.setFont(customFont);
-
- // 设置布局
- QVBoxLayout *layout = new QVBoxLayout;
- layout->addWidget(&label);
-
- QWidget window;
- window.setLayout(layout);
- window.show();
-
- return app.exec();
- }
- auto labelDetails = new QLabel(QString("1235"));
-
- int fontId = QFontDatabase::addApplicationFont("B:/project/mengzong/jianluji/0525/demo/hyyj.ttf");
- if (fontId == -1) {
- qWarning() << "Failed to load font!";
- return ;
- }
-
- // 获取字体系列名称
- QStringList fontFamilies = QFontDatabase::applicationFontFamilies(fontId);
- if (fontFamilies.isEmpty()) {
- qWarning() << "Failed to retrieve font families!";
- return ;
- }
-
- QString fontFamily = fontFamilies.at(0);
-
- QFont customFont(fontFamily);
-
- customFont.setPointSize(48); // 设置字体大小
- labelDetails->setFont(customFont);
-
- labelDetails->setAutoFillBackground(true);
- labelDetails->setStyleSheet("QLabel { color : rgb(39, 255, 167); }");
- labelDetails->setFixedSize(300, 60);
- vbox->addWidget(labelDetails);
int fontId = QFontDatabase::addApplicationFont(":/res/raw/hyyj.ttf");
int fontId = QFontDatabase::addApplicationFont("./hyyj.ttf");
- QT += core gui
-
- greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
-
- TARGET = FontExample
- TEMPLATE = app
-
- # 添加字体文件到资源
- RESOURCES += resources.qrc
"1.0"> -
hyyj.ttf