Upload project files

Upload dtk-font and qt-font demo project files and build script.
This commit is contained in:
2020-10-23 01:33:51 +08:00
parent b646cc685d
commit 77a4b4aace
15 changed files with 307 additions and 66 deletions
+42
View File
@@ -0,0 +1,42 @@
#-------------------------------------------------
#
# Project created by QtCreator 2020-10-23T00:40:00
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = dtk-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 link_pkgconfig
PKGCONFIG += dtkwidget
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
+5
View File
@@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/">
<file>fonts/华康少女字体.ttf</file>
</qresource>
</RCC>
Binary file not shown.
+15
View File
@@ -0,0 +1,15 @@
#include "mainwindow.h"
#include <DApplication>
int main(int argc, char *argv[])
{
DApplication a(argc, argv);
a.loadTranslator(); // 加载翻译
MainWindow w;
w.show();
return a.exec();
}
+68
View File
@@ -0,0 +1,68 @@
#include "mainwindow.h"
#include <QFontDatabase>
#include <QLayout>
MainWindow::MainWindow(DMainWindow *parent)
: DMainWindow(parent),
// 实例化窗口控件
dbutton_1(new DPushButton),
dbutton_2(new DPushButton),
qbutton_1(new QPushButton),
qbutton_2(new QPushButton)
{
// 初始化主窗口
setCentralWidget(w); // 将 w 作为窗口的用户部分(整个窗口除了标题栏的部分)
setFixedSize(800, 300); // 改变窗口大小应当改变 MainWindow 的大小
// 载入字体
int loadedFontID = QFontDatabase::addApplicationFont(":/fonts/华康少女字体.ttf");
QStringList loadedFontFamilies = QFontDatabase::applicationFontFamilies(loadedFontID);
if(!loadedFontFamilies.isEmpty())
font = loadedFontFamilies.at(0);
// 设置按钮样式
dbutton_1->setParent(w);
dbutton_1->resize(300, 100);
dbutton_1->setText("这是一个带有字体样式的 DPushButton");
dbutton_1->setFont(font);
dbutton_2->setParent(w);
dbutton_2->resize(300, 100);
dbutton_2->setText("这是一个没有字体样式的 DPushButton");
qbutton_1->setParent(w);
qbutton_1->resize(300, 100);
qbutton_1->setText("这是一个带有字体样式的 QPushButton");
qbutton_1->setFont(font);
qbutton_2->setParent(w);
qbutton_2->resize(300, 100);
qbutton_2->setText("这是一个没有字体样式的 QPushButton");
// 设置按钮布局
QVBoxLayout *dlayout = new QVBoxLayout;
dlayout->setAlignment(Qt::AlignCenter);
dlayout->addWidget(dbutton_1);
dlayout->addSpacing(50);
dlayout->addWidget(dbutton_2);
QVBoxLayout *qlayout = new QVBoxLayout;
qlayout->setAlignment(Qt::AlignCenter);
qlayout->addWidget(qbutton_1);
qlayout->addSpacing(50);
qlayout->addWidget(qbutton_2);
QHBoxLayout *layout = new QHBoxLayout;
layout->setAlignment(Qt::AlignCenter);
layout->addLayout(dlayout);
layout->addSpacing(50);
layout->addLayout(qlayout);
w->setLayout(layout);
}
MainWindow::~MainWindow()
{
delete w;
}
+29
View File
@@ -0,0 +1,29 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <DMainWindow>
#include <DPushButton>
DWIDGET_USE_NAMESPACE
class MainWindow : public DMainWindow
{
Q_OBJECT
public:
MainWindow(DMainWindow *parent = nullptr);
~MainWindow();
private:
QWidget *w = new QWidget; // w 是窗口的用户区,应当是所有窗口中控件的父(不包含标题栏及其上边的控件)
DPushButton *dbutton_1;
DPushButton *dbutton_2;
QPushButton *qbutton_1;
QPushButton *qbutton_2;
QFont font; // 自定义字体
};
#endif // MAINWINDOW_H