2021-12-08 09:44:30 +00:00
|
|
|
|
#pragma execution_character_set("utf-8")
|
|
|
|
|
|
|
|
|
|
#include "frmmain.h"
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QTextCodec>
|
2022-01-14 09:16:17 +00:00
|
|
|
|
#include <QFontDatabase>
|
2021-12-10 12:23:28 +00:00
|
|
|
|
#include <QTime>
|
|
|
|
|
#include <QDebug>
|
2021-12-08 09:44:30 +00:00
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
|
{
|
2022-01-14 09:16:17 +00:00
|
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
|
|
|
|
|
QApplication::setAttribute(Qt::AA_Use96Dpi);
|
|
|
|
|
#endif
|
2021-12-08 09:44:30 +00:00
|
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
|
|
|
|
|
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor);
|
|
|
|
|
#endif
|
2022-01-14 09:16:17 +00:00
|
|
|
|
|
2021-12-08 09:44:30 +00:00
|
|
|
|
QApplication a(argc, argv);
|
2022-01-13 03:27:55 +00:00
|
|
|
|
QFont font;
|
2022-01-14 09:16:17 +00:00
|
|
|
|
#ifdef Q_OS_WASM
|
|
|
|
|
QString fontFile = ":/font/DroidSansFallback.ttf";
|
|
|
|
|
QString fontName = "Droid Sans Fallback";
|
|
|
|
|
|
|
|
|
|
//判断图形字体是否存在,不存在则加入
|
|
|
|
|
QFontDatabase fontDb;
|
|
|
|
|
if (!fontDb.families().contains(fontName)) {
|
|
|
|
|
int fontId = fontDb.addApplicationFont(fontFile);
|
|
|
|
|
QStringList listName = fontDb.applicationFontFamilies(fontId);
|
|
|
|
|
if (listName.count() == 0) {
|
|
|
|
|
qDebug() << QString("load %1 error").arg(fontName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//再次判断是否包含字体名称防止加载失败
|
|
|
|
|
if (fontDb.families().contains(fontName)) {
|
|
|
|
|
font = QFont(fontName);
|
|
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(4,8,0))
|
|
|
|
|
font.setHintingPreference(QFont::PreferNoHinting);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
#else
|
2022-01-13 03:27:55 +00:00
|
|
|
|
font.setFamily("Microsoft Yahei");
|
|
|
|
|
font.setPixelSize(13);
|
2022-01-14 09:16:17 +00:00
|
|
|
|
#endif
|
2022-01-13 03:27:55 +00:00
|
|
|
|
a.setFont(font);
|
2021-12-08 09:44:30 +00:00
|
|
|
|
|
|
|
|
|
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
|
|
|
|
|
#if _MSC_VER
|
|
|
|
|
QTextCodec *codec = QTextCodec::codecForName("gbk");
|
|
|
|
|
#else
|
|
|
|
|
QTextCodec *codec = QTextCodec::codecForName("utf-8");
|
|
|
|
|
#endif
|
|
|
|
|
QTextCodec::setCodecForLocale(codec);
|
|
|
|
|
QTextCodec::setCodecForCStrings(codec);
|
|
|
|
|
QTextCodec::setCodecForTr(codec);
|
|
|
|
|
#else
|
|
|
|
|
QTextCodec *codec = QTextCodec::codecForName("utf-8");
|
|
|
|
|
QTextCodec::setCodecForLocale(codec);
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-12-10 12:23:28 +00:00
|
|
|
|
//初始化随机数种子
|
|
|
|
|
QTime t = QTime::currentTime();
|
|
|
|
|
srand(t.msec() + t.second() * 1000);
|
|
|
|
|
|
2021-12-08 09:44:30 +00:00
|
|
|
|
frmMain w;
|
|
|
|
|
w.setWindowTitle("qcustomplot示例 (QQ: 517216493 WX: feiyangqingyun)");
|
|
|
|
|
w.resize(1000, 650);
|
|
|
|
|
w.show();
|
|
|
|
|
|
|
|
|
|
return a.exec();
|
|
|
|
|
}
|