Upload project files
Upload dtk-font and qt-font demo project files and build script.
This commit is contained in:
5
qt-font/fonts.qrc
Normal file
5
qt-font/fonts.qrc
Normal file
@@ -0,0 +1,5 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>fonts/华康少女字体.ttf</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
BIN
qt-font/fonts/华康少女字体.ttf
Normal file
BIN
qt-font/fonts/华康少女字体.ttf
Normal file
Binary file not shown.
13
qt-font/main.cpp
Normal file
13
qt-font/main.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#include "mainwindow.h"
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
|
||||
MainWindow w;
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
45
qt-font/mainwindow.cpp
Normal file
45
qt-font/mainwindow.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "mainwindow.h"
|
||||
|
||||
#include <QFontDatabase>
|
||||
#include <QLayout>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent),
|
||||
// 实例化窗口控件
|
||||
button_1(new QPushButton),
|
||||
button_2(new QPushButton)
|
||||
{
|
||||
// 初始化主窗口
|
||||
setCentralWidget(w); // 将 w 作为窗口的用户部分
|
||||
setFixedSize(400, 300); // 改变窗口大小应当改变 MainWindow 的大小
|
||||
|
||||
// 载入字体
|
||||
int loadedFontID = QFontDatabase::addApplicationFont(":/fonts/华康少女字体.ttf");
|
||||
QStringList loadedFontFamilies = QFontDatabase::applicationFontFamilies(loadedFontID);
|
||||
if(!loadedFontFamilies.isEmpty())
|
||||
font = loadedFontFamilies.at(0);
|
||||
|
||||
// 设置按钮样式
|
||||
button_1->setParent(w);
|
||||
button_1->resize(300, 100);
|
||||
button_1->setText("这是一个带有字体样式的 QPushButton");
|
||||
button_1->setFont(font);
|
||||
|
||||
button_2->setParent(w);
|
||||
button_2->resize(300, 100);
|
||||
button_2->setText("这是一个没有字体样式的 QPushButton");
|
||||
|
||||
// 设置按钮布局
|
||||
QVBoxLayout *layout = new QVBoxLayout;
|
||||
layout->setAlignment(Qt::AlignCenter);
|
||||
layout->addWidget(button_1);
|
||||
layout->addSpacing(50);
|
||||
layout->addWidget(button_2);
|
||||
|
||||
w->setLayout(layout);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete w;
|
||||
}
|
||||
24
qt-font/mainwindow.h
Normal file
24
qt-font/mainwindow.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QPushButton>
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MainWindow(QWidget *parent = nullptr);
|
||||
~MainWindow();
|
||||
|
||||
private:
|
||||
QWidget *w = new QWidget; // w 是窗口的用户区,应当是所有窗口中控件的父
|
||||
|
||||
QPushButton *button_1;
|
||||
QPushButton *button_2;
|
||||
|
||||
QFont font; // 自定义字体
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
40
qt-font/qt-font.pro
Normal file
40
qt-font/qt-font.pro
Normal file
@@ -0,0 +1,40 @@
|
||||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2020-10-22T23:50:10
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core gui
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
||||
TARGET = qt-font
|
||||
TEMPLATE = app
|
||||
|
||||
# The following define makes your compiler emit warnings if you use
|
||||
# any feature of Qt which has been marked as deprecated (the exact warnings
|
||||
# depend on your compiler). Please consult the documentation of the
|
||||
# deprecated API in order to know how to port your code away from it.
|
||||
DEFINES += QT_DEPRECATED_WARNINGS
|
||||
|
||||
# You can also make your code fail to compile if you use deprecated APIs.
|
||||
# In order to do so, uncomment the following line.
|
||||
# You can also select to disable deprecated APIs only up to a certain version of Qt.
|
||||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||
|
||||
CONFIG += c++11
|
||||
|
||||
SOURCES += \
|
||||
main.cpp \
|
||||
mainwindow.cpp
|
||||
|
||||
HEADERS += \
|
||||
mainwindow.h
|
||||
|
||||
# Default rules for deployment.
|
||||
qnx: target.path = /tmp/$${TARGET}/bin
|
||||
else: unix:!android: target.path = /opt/$${TARGET}/bin
|
||||
!isEmpty(target.path): INSTALLS += target
|
||||
|
||||
RESOURCES += \
|
||||
fonts.qrc
|
||||
Reference in New Issue
Block a user