-
Notifications
You must be signed in to change notification settings - Fork 364
/
main.cpp
45 lines (39 loc) · 1.83 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QQuickWindow>
#include <QFontDatabase>
#include <QFont>
#include "mywindow.h"
int main(int argc, char *argv[])
{
// 如果是 EnableHighDpiScaling,Screen.devicePixelRatio 就是 Qt 内部使用的缩放系数
// 默认是四舍五入整数倍,加上 PassThrough 后才有非整数倍缩放值
// 如果是 DisableHighDpiScaling,Screen.devicePixelRatio 始终为 1
// 注意:HighDpiScaling 设置只在 Qt5 可用,而且 Qt5 和 Qt6 QWindow 内部实现也不一样
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
//QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling);
QQuickWindow::setTextRenderType(QQuickWindow::NativeTextRendering);
QApplication app(argc, argv);
QFont font = app.font();
// font.setFamily("SimSun");
font.setPixelSize(14);
app.setFont(font);
qDebug()<<"app"<<font.family();
font = QFontDatabase::systemFont(QFontDatabase::GeneralFont);
qDebug()<<"sys"<<font.family();
qmlRegisterType<MyQuickWindow>("Test", 2, 15, "MyWindow");
// QWindow 里面用了很多 Q_REVISION 宏做版本控制
// 继承后的 QML 组件不能直接访问这些属性,需要注册下相关类型的 REVISION
qmlRegisterRevision<QQuickWindow, 15>("Test", 2, 15);
qmlRegisterRevision<QWindow, 15>("Test", 2, 15);
QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
engine.load(url);
return app.exec();
}