更新代码

master
feiyangqingyun 2022-01-13 11:27:55 +08:00
parent 6eea8cbbee
commit a534d2a228
75 changed files with 943 additions and 264 deletions

View File

@ -7,7 +7,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -7,7 +7,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -7,7 +7,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -7,7 +7,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -5,7 +5,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -33,8 +33,6 @@ LightButton::LightButton(QWidget *parent) : QWidget(parent)
timerAlarm = new QTimer(this); timerAlarm = new QTimer(this);
connect(timerAlarm, SIGNAL(timeout()), this, SLOT(alarm())); connect(timerAlarm, SIGNAL(timeout()), this, SLOT(alarm()));
timerAlarm->setInterval(500); timerAlarm->setInterval(500);
//setFont(QFont("Arial", 8));
} }
bool LightButton::eventFilter(QObject *watched, QEvent *event) bool LightButton::eventFilter(QObject *watched, QEvent *event)

View File

@ -7,7 +7,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -7,7 +7,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -7,7 +7,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -9,6 +9,7 @@
#include "qdatetime.h" #include "qdatetime.h"
#include "qapplication.h" #include "qapplication.h"
#include "qtimer.h" #include "qtimer.h"
#include "qtextstream.h"
#include "qstringlist.h" #include "qstringlist.h"
#define QDATE qPrintable(QDate::currentDate().toString("yyyy-MM-dd")) #define QDATE qPrintable(QDate::currentDate().toString("yyyy-MM-dd"))

View File

@ -7,7 +7,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -7,7 +7,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -7,7 +7,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

File diff suppressed because one or more lines are too long

View File

@ -10,7 +10,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -7,7 +7,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -7,7 +7,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -7,7 +7,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -7,7 +7,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION <= QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -7,7 +7,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -7,7 +7,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -7,7 +7,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -7,7 +7,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -13,7 +13,10 @@ int main(int argc, char *argv[])
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor); QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor);
#endif #endif
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -7,7 +7,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -7,7 +7,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -7,7 +7,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -1,5 +1,6 @@
#include "quihelper.h" #include "quihelper.h"
#define TIMEMS qPrintable(QTime::currentTime().toString("HH:mm:ss zzz"))
int QUIHelper::getScreenIndex() int QUIHelper::getScreenIndex()
{ {
//需要对多个屏幕进行处理 //需要对多个屏幕进行处理
@ -57,6 +58,11 @@ int QUIHelper::deskHeight()
return getScreenRect().height(); return getScreenRect().height();
} }
QSize QUIHelper::deskSize()
{
return getScreenRect().size();
}
QWidget *QUIHelper::centerBaseForm = 0; QWidget *QUIHelper::centerBaseForm = 0;
void QUIHelper::setFormInCenter(QWidget *form) void QUIHelper::setFormInCenter(QWidget *form)
{ {
@ -77,6 +83,19 @@ void QUIHelper::setFormInCenter(QWidget *form)
form->move(movePoint); form->move(movePoint);
} }
void QUIHelper::showForm(QWidget *form)
{
setFormInCenter(form);
//判断宽高是否超过了屏幕分辨率,超过了则最大化显示
//qDebug() << TIMEMS << form->size() << deskSize();
if (form->width() + 20 > deskWidth() || form->height() + 50 > deskHeight()) {
form->showMaximized();
} else {
form->show();
}
}
QString QUIHelper::appName() QString QUIHelper::appName()
{ {
//没有必要每次都获取,只有当变量为空时才去获取一次 //没有必要每次都获取,只有当变量为空时才去获取一次
@ -101,12 +120,36 @@ QString QUIHelper::appPath()
#endif #endif
} }
QString QUIHelper::getUuid() QList<QColor> QUIHelper::colors = QList<QColor>();
QList<QColor> QUIHelper::getColorList()
{ {
QString uuid = QUuid::createUuid().toString(); //备用颜色集合 可以自行添加
uuid.replace("{", ""); if (colors.count() == 0) {
uuid.replace("}", ""); colors << QColor(0, 176, 180) << QColor(0, 113, 193) << QColor(255, 192, 0);
return uuid; colors << QColor(72, 103, 149) << QColor(185, 87, 86) << QColor(0, 177, 125);
colors << QColor(214, 77, 84) << QColor(71, 164, 233) << QColor(34, 163, 169);
colors << QColor(59, 123, 156) << QColor(162, 121, 197) << QColor(72, 202, 245);
colors << QColor(0, 150, 121) << QColor(111, 9, 176) << QColor(250, 170, 20);
}
return colors;
}
QStringList QUIHelper::getColorNames()
{
QList<QColor> colors = getColorList();
QStringList colorNames;
foreach (QColor color, colors) {
colorNames << color.name();
}
return colorNames;
}
QColor QUIHelper::getRandColor()
{
QList<QColor> colors = getColorList();
int index = getRandValue(0, colors.count(), true);
return colors.at(index);
} }
void QUIHelper::initRand() void QUIHelper::initRand()
@ -116,6 +159,82 @@ void QUIHelper::initRand()
srand(t.msec() + t.second() * 1000); srand(t.msec() + t.second() * 1000);
} }
float QUIHelper::getRandFloat(float min, float max)
{
double diff = fabs(max - min);
double value = (double)(rand() % 100) / 100;
value = min + value * diff;
return value;
}
double QUIHelper::getRandValue(int min, int max, bool contansMin, bool contansMax)
{
int value;
#if (QT_VERSION <= QT_VERSION_CHECK(5,10,0))
//通用公式 a是起始值,n是整数的范围
//int value = a + rand() % n;
if (contansMin) {
if (contansMax) {
value = min + 0 + (rand() % (max - min + 1));
} else {
value = min + 0 + (rand() % (max - min + 0));
}
} else {
if (contansMax) {
value = min + 1 + (rand() % (max - min + 0));
} else {
value = min + 1 + (rand() % (max - min - 1));
}
}
#else
if (contansMin) {
if (contansMax) {
value = QRandomGenerator::global()->bounded(min + 0, max + 1);
} else {
value = QRandomGenerator::global()->bounded(min + 0, max + 0);
}
} else {
if (contansMax) {
value = QRandomGenerator::global()->bounded(min + 1, max + 1);
} else {
value = QRandomGenerator::global()->bounded(min + 1, max + 0);
}
}
#endif
return value;
}
QStringList QUIHelper::getRandPoint(int count, float mainLng, float mainLat, float dotLng, float dotLat)
{
//随机生成点坐标
QStringList points;
for (int i = 0; i < count; ++i) {
//0.00881415 0.000442928
#if (QT_VERSION >= QT_VERSION_CHECK(5,10,0))
float lngx = QRandomGenerator::global()->bounded(dotLng);
float latx = QRandomGenerator::global()->bounded(dotLat);
#else
float lngx = getRandFloat(dotLng / 10, dotLng);
float latx = getRandFloat(dotLat / 10, dotLat);
#endif
//需要先用精度转换成字符串
QString lng2 = QString::number(mainLng + lngx, 'f', 8);
QString lat2 = QString::number(mainLat + latx, 'f', 8);
QString point = QString("%1,%2").arg(lng2).arg(lat2);
points << point;
}
return points;
}
QString QUIHelper::getUuid()
{
QString uuid = QUuid::createUuid().toString();
uuid.replace("{", "");
uuid.replace("}", "");
return uuid;
}
void QUIHelper::newDir(const QString &dirName) void QUIHelper::newDir(const QString &dirName)
{ {
QString strDir = dirName; QString strDir = dirName;
@ -151,30 +270,68 @@ void QUIHelper::sleep(int msec)
void QUIHelper::setStyle() void QUIHelper::setStyle()
{ {
//打印下所有内置风格的名字 //打印下所有内置风格的名字
qDebug() << "Qt内置的样式" << QStyleFactory::keys(); qDebug() << TIMEMS << "QStyleFactory::keys" << QStyleFactory::keys();
//设置内置风格
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
qApp->setStyle(QStyleFactory::create("Fusion")); qApp->setStyle(QStyleFactory::create("Fusion"));
#else #else
qApp->setStyle(QStyleFactory::create("Cleanlooks")); qApp->setStyle(QStyleFactory::create("Cleanlooks"));
#endif #endif
//qApp->setPalette(QPalette("#FFFFFF"));
//设置指定颜色
QPalette palette;
palette.setBrush(QPalette::Window, QColor("#F0F0F0"));
qApp->setPalette(palette);
}
QFont QUIHelper::addFont(const QString &fontFile, const QString &fontName)
{
//判断图形字体是否存在,不存在则加入
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);
}
}
//再次判断是否包含字体名称防止加载失败
QFont font;
if (fontDb.families().contains(fontName)) {
font = QFont(fontName);
#if (QT_VERSION >= QT_VERSION_CHECK(4,8,0))
font.setHintingPreference(QFont::PreferNoHinting);
#endif
}
return font;
} }
void QUIHelper::setFont(int fontSize) void QUIHelper::setFont(int fontSize)
{ {
QFont font; #ifdef rk3399
font.setFamily("MicroSoft Yahei"); return;
#ifdef Q_OS_ANDROID #endif
font.setPixelSize(15); //网页套件需要主动加载中文字体才能正常显示中文
#elif __arm__ #ifdef Q_OS_WASM
font.setPixelSize(25); QString fontFile = ":/font/DroidSansFallback.ttf";
#else QString fontName = "Droid Sans Fallback";
font.setPixelSize(fontSize); qApp->setFont(addFont(fontFile, fontName));
return;
#endif #endif
#ifndef rk3399 #ifdef __arm__
qApp->setFont(font); fontSize = 25;
#endif #endif
#ifdef Q_OS_ANDROID
fontSize = 15;
#endif
QFont font;
font.setFamily("MicroSoft Yahei");
font.setPixelSize(fontSize);
qApp->setFont(font);
} }
void QUIHelper::setCode(bool utf8) void QUIHelper::setCode(bool utf8)
@ -205,20 +362,23 @@ void QUIHelper::setTranslator(const QString &qmFile)
} }
QTranslator *translator = new QTranslator(qApp); QTranslator *translator = new QTranslator(qApp);
translator->load(qmFile); if (translator->load(qmFile)) {
qApp->installTranslator(translator); qApp->installTranslator(translator);
}
} }
void QUIHelper::initAll() void QUIHelper::initAll(bool utf8, bool style, int fontSize)
{ {
//初始化随机数种子 //初始化随机数种子
QUIHelper::initRand(); QUIHelper::initRand();
//设置样式风格
QUIHelper::setStyle();
//设置字体
QUIHelper::setFont(13);
//设置编码 //设置编码
QUIHelper::setCode(); QUIHelper::setCode(utf8);
//设置样式风格
if (style) {
QUIHelper::setStyle();
}
//设置字体
QUIHelper::setFont(fontSize);
//设置翻译文件支持多个 //设置翻译文件支持多个
QUIHelper::setTranslator(":/qm/widgets.qm"); QUIHelper::setTranslator(":/qm/widgets.qm");
QUIHelper::setTranslator(":/qm/qt_zh_CN.qm"); QUIHelper::setTranslator(":/qm/qt_zh_CN.qm");
@ -299,7 +459,12 @@ QString QUIHelper::getXorEncryptDecrypt(const QString &value, char key)
key = 127; key = 127;
} }
//大概从5.9版本输出的加密密码字符串前面会加上 @String 字符
QString result = value; QString result = value;
if (result.startsWith("@String")) {
result = result.mid(8, result.length() - 9);
}
int count = result.count(); int count = result.count();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
result[i] = QChar(result.at(i).toLatin1() ^ key); result[i] = QChar(result.at(i).toLatin1() ^ key);
@ -331,6 +496,8 @@ uchar QUIHelper::getCheckCode(const QByteArray &data)
void QUIHelper::initTableView(QTableView *tableView, int rowHeight, bool headVisible, bool edit, bool stretchLast) void QUIHelper::initTableView(QTableView *tableView, int rowHeight, bool headVisible, bool edit, bool stretchLast)
{ {
//设置弱属性用于应用qss特殊样式
tableView->setProperty("model", true);
//取消自动换行 //取消自动换行
tableView->setWordWrap(false); tableView->setWordWrap(false);
//超出文本不显示省略号 //超出文本不显示省略号
@ -374,7 +541,8 @@ void QUIHelper::openFile(const QString &fileName, const QString &msg)
#ifdef __arm__ #ifdef __arm__
return; return;
#endif #endif
if (fileName.isEmpty()) { //文件不存在则不用处理
if (!QFile(fileName).exists()) {
return; return;
} }
if (QUIHelper::showMessageBoxQuestion(msg + "成功!确定现在就打开吗?") == QMessageBox::Yes) { if (QUIHelper::showMessageBoxQuestion(msg + "成功!确定现在就打开吗?") == QMessageBox::Yes) {
@ -401,8 +569,10 @@ bool QUIHelper::checkIniFile(const QString &iniFile)
QStringList list = line.split("="); QStringList list = line.split("=");
if (list.count() == 2) { if (list.count() == 2) {
if (list.at(1) == "") { QString key = list.at(0);
qDebug() << "ini node no value" << list.at(0); QString value = list.at(1);
if (value.isEmpty()) {
qDebug() << TIMEMS << "ini node no value" << key;
ok = false; ok = false;
break; break;
} }

View File

@ -13,29 +13,52 @@ public:
//获取桌面宽度高度+居中显示 //获取桌面宽度高度+居中显示
static int deskWidth(); static int deskWidth();
static int deskHeight(); static int deskHeight();
static QSize deskSize();
//居中显示窗体 //居中显示窗体
//定义标志位指定是以桌面为参照还是主程序界面为参照 //定义标志位指定是以桌面为参照还是主程序界面为参照
static QWidget *centerBaseForm; static QWidget *centerBaseForm;
static void setFormInCenter(QWidget *form); static void setFormInCenter(QWidget *form);
static void showForm(QWidget *form);
//程序文件名称+当前所在路径 //程序文件名称+当前所在路径
static QString appName(); static QString appName();
static QString appPath(); static QString appPath();
//获取uuid+初始化随机数种子+新建目录+延时 //获取内置颜色集合
static QString getUuid(); static QList<QColor> colors;
static QList<QColor> getColorList();
static QStringList getColorNames();
//随机获取颜色集合中的颜色
static QColor getRandColor();
//初始化随机数种子
static void initRand(); static void initRand();
//获取随机小数
static float getRandFloat(float min, float max);
//获取随机数,指定最小值和最大值
static double getRandValue(int min, int max, bool contansMin = false, bool contansMax = false);
//获取范围值随机经纬度集合
static QStringList getRandPoint(int count, float mainLng, float mainLat, float dotLng, float dotLat);
//获取uuid
static QString getUuid();
//可执行文件目录下新建目录
static void newDir(const QString &dirName); static void newDir(const QString &dirName);
//延时
static void sleep(int msec); static void sleep(int msec);
//设置样式+字体+编码+居中+翻译 //设置Qt自带样式
static void setStyle(); static void setStyle();
//设置字体
static QFont addFont(const QString &fontFile, const QString &fontName);
static void setFont(int fontSize = 12); static void setFont(int fontSize = 12);
//设置编码
static void setCode(bool utf8 = true); static void setCode(bool utf8 = true);
//设置翻译文件
static void setTranslator(const QString &qmFile); static void setTranslator(const QString &qmFile);
//一次性设置所有 //一次性设置所有
static void initAll(); static void initAll(bool utf8 = true, bool style = true, int fontSize = 13);
//设置无边框 //设置无边框
static void setFramelessForm(QWidget *widgetMain, bool tool = false, bool top = false, bool menu = true); static void setFramelessForm(QWidget *widgetMain, bool tool = false, bool top = false, bool menu = true);

View File

@ -3,9 +3,13 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
QApplication::setAttribute(Qt::AA_Use96Dpi);
#endif
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0)) #if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor); QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor);
#endif #endif
QApplication a(argc, argv); QApplication a(argc, argv);
a.setWindowIcon(QIcon(":/main.ico")); a.setWindowIcon(QIcon(":/main.ico"));

View File

@ -7,7 +7,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -7,7 +7,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -8,7 +8,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -7,7 +7,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -8,7 +8,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -7,7 +7,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -1,5 +1,6 @@
#include "quihelper.h" #include "quihelper.h"
#define TIMEMS qPrintable(QTime::currentTime().toString("HH:mm:ss zzz"))
int QUIHelper::getScreenIndex() int QUIHelper::getScreenIndex()
{ {
//需要对多个屏幕进行处理 //需要对多个屏幕进行处理
@ -57,6 +58,11 @@ int QUIHelper::deskHeight()
return getScreenRect().height(); return getScreenRect().height();
} }
QSize QUIHelper::deskSize()
{
return getScreenRect().size();
}
QWidget *QUIHelper::centerBaseForm = 0; QWidget *QUIHelper::centerBaseForm = 0;
void QUIHelper::setFormInCenter(QWidget *form) void QUIHelper::setFormInCenter(QWidget *form)
{ {
@ -77,6 +83,19 @@ void QUIHelper::setFormInCenter(QWidget *form)
form->move(movePoint); form->move(movePoint);
} }
void QUIHelper::showForm(QWidget *form)
{
setFormInCenter(form);
//判断宽高是否超过了屏幕分辨率,超过了则最大化显示
//qDebug() << TIMEMS << form->size() << deskSize();
if (form->width() + 20 > deskWidth() || form->height() + 50 > deskHeight()) {
form->showMaximized();
} else {
form->show();
}
}
QString QUIHelper::appName() QString QUIHelper::appName()
{ {
//没有必要每次都获取,只有当变量为空时才去获取一次 //没有必要每次都获取,只有当变量为空时才去获取一次
@ -101,12 +120,36 @@ QString QUIHelper::appPath()
#endif #endif
} }
QString QUIHelper::getUuid() QList<QColor> QUIHelper::colors = QList<QColor>();
QList<QColor> QUIHelper::getColorList()
{ {
QString uuid = QUuid::createUuid().toString(); //备用颜色集合 可以自行添加
uuid.replace("{", ""); if (colors.count() == 0) {
uuid.replace("}", ""); colors << QColor(0, 176, 180) << QColor(0, 113, 193) << QColor(255, 192, 0);
return uuid; colors << QColor(72, 103, 149) << QColor(185, 87, 86) << QColor(0, 177, 125);
colors << QColor(214, 77, 84) << QColor(71, 164, 233) << QColor(34, 163, 169);
colors << QColor(59, 123, 156) << QColor(162, 121, 197) << QColor(72, 202, 245);
colors << QColor(0, 150, 121) << QColor(111, 9, 176) << QColor(250, 170, 20);
}
return colors;
}
QStringList QUIHelper::getColorNames()
{
QList<QColor> colors = getColorList();
QStringList colorNames;
foreach (QColor color, colors) {
colorNames << color.name();
}
return colorNames;
}
QColor QUIHelper::getRandColor()
{
QList<QColor> colors = getColorList();
int index = getRandValue(0, colors.count(), true);
return colors.at(index);
} }
void QUIHelper::initRand() void QUIHelper::initRand()
@ -116,6 +159,82 @@ void QUIHelper::initRand()
srand(t.msec() + t.second() * 1000); srand(t.msec() + t.second() * 1000);
} }
float QUIHelper::getRandFloat(float min, float max)
{
double diff = fabs(max - min);
double value = (double)(rand() % 100) / 100;
value = min + value * diff;
return value;
}
double QUIHelper::getRandValue(int min, int max, bool contansMin, bool contansMax)
{
int value;
#if (QT_VERSION <= QT_VERSION_CHECK(5,10,0))
//通用公式 a是起始值,n是整数的范围
//int value = a + rand() % n;
if (contansMin) {
if (contansMax) {
value = min + 0 + (rand() % (max - min + 1));
} else {
value = min + 0 + (rand() % (max - min + 0));
}
} else {
if (contansMax) {
value = min + 1 + (rand() % (max - min + 0));
} else {
value = min + 1 + (rand() % (max - min - 1));
}
}
#else
if (contansMin) {
if (contansMax) {
value = QRandomGenerator::global()->bounded(min + 0, max + 1);
} else {
value = QRandomGenerator::global()->bounded(min + 0, max + 0);
}
} else {
if (contansMax) {
value = QRandomGenerator::global()->bounded(min + 1, max + 1);
} else {
value = QRandomGenerator::global()->bounded(min + 1, max + 0);
}
}
#endif
return value;
}
QStringList QUIHelper::getRandPoint(int count, float mainLng, float mainLat, float dotLng, float dotLat)
{
//随机生成点坐标
QStringList points;
for (int i = 0; i < count; ++i) {
//0.00881415 0.000442928
#if (QT_VERSION >= QT_VERSION_CHECK(5,10,0))
float lngx = QRandomGenerator::global()->bounded(dotLng);
float latx = QRandomGenerator::global()->bounded(dotLat);
#else
float lngx = getRandFloat(dotLng / 10, dotLng);
float latx = getRandFloat(dotLat / 10, dotLat);
#endif
//需要先用精度转换成字符串
QString lng2 = QString::number(mainLng + lngx, 'f', 8);
QString lat2 = QString::number(mainLat + latx, 'f', 8);
QString point = QString("%1,%2").arg(lng2).arg(lat2);
points << point;
}
return points;
}
QString QUIHelper::getUuid()
{
QString uuid = QUuid::createUuid().toString();
uuid.replace("{", "");
uuid.replace("}", "");
return uuid;
}
void QUIHelper::newDir(const QString &dirName) void QUIHelper::newDir(const QString &dirName)
{ {
QString strDir = dirName; QString strDir = dirName;
@ -151,30 +270,68 @@ void QUIHelper::sleep(int msec)
void QUIHelper::setStyle() void QUIHelper::setStyle()
{ {
//打印下所有内置风格的名字 //打印下所有内置风格的名字
qDebug() << "Qt内置的样式" << QStyleFactory::keys(); qDebug() << TIMEMS << "QStyleFactory::keys" << QStyleFactory::keys();
//设置内置风格
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
qApp->setStyle(QStyleFactory::create("Fusion")); qApp->setStyle(QStyleFactory::create("Fusion"));
#else #else
qApp->setStyle(QStyleFactory::create("Cleanlooks")); qApp->setStyle(QStyleFactory::create("Cleanlooks"));
#endif #endif
//qApp->setPalette(QPalette("#FFFFFF"));
//设置指定颜色
QPalette palette;
palette.setBrush(QPalette::Window, QColor("#F0F0F0"));
qApp->setPalette(palette);
}
QFont QUIHelper::addFont(const QString &fontFile, const QString &fontName)
{
//判断图形字体是否存在,不存在则加入
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);
}
}
//再次判断是否包含字体名称防止加载失败
QFont font;
if (fontDb.families().contains(fontName)) {
font = QFont(fontName);
#if (QT_VERSION >= QT_VERSION_CHECK(4,8,0))
font.setHintingPreference(QFont::PreferNoHinting);
#endif
}
return font;
} }
void QUIHelper::setFont(int fontSize) void QUIHelper::setFont(int fontSize)
{ {
QFont font; #ifdef rk3399
font.setFamily("MicroSoft Yahei"); return;
#ifdef Q_OS_ANDROID #endif
font.setPixelSize(15); //网页套件需要主动加载中文字体才能正常显示中文
#elif __arm__ #ifdef Q_OS_WASM
font.setPixelSize(25); QString fontFile = ":/font/DroidSansFallback.ttf";
#else QString fontName = "Droid Sans Fallback";
font.setPixelSize(fontSize); qApp->setFont(addFont(fontFile, fontName));
return;
#endif #endif
#ifndef rk3399 #ifdef __arm__
qApp->setFont(font); fontSize = 25;
#endif #endif
#ifdef Q_OS_ANDROID
fontSize = 15;
#endif
QFont font;
font.setFamily("MicroSoft Yahei");
font.setPixelSize(fontSize);
qApp->setFont(font);
} }
void QUIHelper::setCode(bool utf8) void QUIHelper::setCode(bool utf8)
@ -205,20 +362,23 @@ void QUIHelper::setTranslator(const QString &qmFile)
} }
QTranslator *translator = new QTranslator(qApp); QTranslator *translator = new QTranslator(qApp);
translator->load(qmFile); if (translator->load(qmFile)) {
qApp->installTranslator(translator); qApp->installTranslator(translator);
}
} }
void QUIHelper::initAll() void QUIHelper::initAll(bool utf8, bool style, int fontSize)
{ {
//初始化随机数种子 //初始化随机数种子
QUIHelper::initRand(); QUIHelper::initRand();
//设置样式风格
QUIHelper::setStyle();
//设置字体
QUIHelper::setFont(13);
//设置编码 //设置编码
QUIHelper::setCode(); QUIHelper::setCode(utf8);
//设置样式风格
if (style) {
QUIHelper::setStyle();
}
//设置字体
QUIHelper::setFont(fontSize);
//设置翻译文件支持多个 //设置翻译文件支持多个
QUIHelper::setTranslator(":/qm/widgets.qm"); QUIHelper::setTranslator(":/qm/widgets.qm");
QUIHelper::setTranslator(":/qm/qt_zh_CN.qm"); QUIHelper::setTranslator(":/qm/qt_zh_CN.qm");
@ -299,7 +459,12 @@ QString QUIHelper::getXorEncryptDecrypt(const QString &value, char key)
key = 127; key = 127;
} }
//大概从5.9版本输出的加密密码字符串前面会加上 @String 字符
QString result = value; QString result = value;
if (result.startsWith("@String")) {
result = result.mid(8, result.length() - 9);
}
int count = result.count(); int count = result.count();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
result[i] = QChar(result.at(i).toLatin1() ^ key); result[i] = QChar(result.at(i).toLatin1() ^ key);
@ -331,6 +496,8 @@ uchar QUIHelper::getCheckCode(const QByteArray &data)
void QUIHelper::initTableView(QTableView *tableView, int rowHeight, bool headVisible, bool edit, bool stretchLast) void QUIHelper::initTableView(QTableView *tableView, int rowHeight, bool headVisible, bool edit, bool stretchLast)
{ {
//设置弱属性用于应用qss特殊样式
tableView->setProperty("model", true);
//取消自动换行 //取消自动换行
tableView->setWordWrap(false); tableView->setWordWrap(false);
//超出文本不显示省略号 //超出文本不显示省略号
@ -374,7 +541,8 @@ void QUIHelper::openFile(const QString &fileName, const QString &msg)
#ifdef __arm__ #ifdef __arm__
return; return;
#endif #endif
if (fileName.isEmpty()) { //文件不存在则不用处理
if (!QFile(fileName).exists()) {
return; return;
} }
if (QUIHelper::showMessageBoxQuestion(msg + "成功!确定现在就打开吗?") == QMessageBox::Yes) { if (QUIHelper::showMessageBoxQuestion(msg + "成功!确定现在就打开吗?") == QMessageBox::Yes) {
@ -401,8 +569,10 @@ bool QUIHelper::checkIniFile(const QString &iniFile)
QStringList list = line.split("="); QStringList list = line.split("=");
if (list.count() == 2) { if (list.count() == 2) {
if (list.at(1) == "") { QString key = list.at(0);
qDebug() << "ini node no value" << list.at(0); QString value = list.at(1);
if (value.isEmpty()) {
qDebug() << TIMEMS << "ini node no value" << key;
ok = false; ok = false;
break; break;
} }

View File

@ -13,29 +13,52 @@ public:
//获取桌面宽度高度+居中显示 //获取桌面宽度高度+居中显示
static int deskWidth(); static int deskWidth();
static int deskHeight(); static int deskHeight();
static QSize deskSize();
//居中显示窗体 //居中显示窗体
//定义标志位指定是以桌面为参照还是主程序界面为参照 //定义标志位指定是以桌面为参照还是主程序界面为参照
static QWidget *centerBaseForm; static QWidget *centerBaseForm;
static void setFormInCenter(QWidget *form); static void setFormInCenter(QWidget *form);
static void showForm(QWidget *form);
//程序文件名称+当前所在路径 //程序文件名称+当前所在路径
static QString appName(); static QString appName();
static QString appPath(); static QString appPath();
//获取uuid+初始化随机数种子+新建目录+延时 //获取内置颜色集合
static QString getUuid(); static QList<QColor> colors;
static QList<QColor> getColorList();
static QStringList getColorNames();
//随机获取颜色集合中的颜色
static QColor getRandColor();
//初始化随机数种子
static void initRand(); static void initRand();
//获取随机小数
static float getRandFloat(float min, float max);
//获取随机数,指定最小值和最大值
static double getRandValue(int min, int max, bool contansMin = false, bool contansMax = false);
//获取范围值随机经纬度集合
static QStringList getRandPoint(int count, float mainLng, float mainLat, float dotLng, float dotLat);
//获取uuid
static QString getUuid();
//可执行文件目录下新建目录
static void newDir(const QString &dirName); static void newDir(const QString &dirName);
//延时
static void sleep(int msec); static void sleep(int msec);
//设置样式+字体+编码+居中+翻译 //设置Qt自带样式
static void setStyle(); static void setStyle();
//设置字体
static QFont addFont(const QString &fontFile, const QString &fontName);
static void setFont(int fontSize = 12); static void setFont(int fontSize = 12);
//设置编码
static void setCode(bool utf8 = true); static void setCode(bool utf8 = true);
//设置翻译文件
static void setTranslator(const QString &qmFile); static void setTranslator(const QString &qmFile);
//一次性设置所有 //一次性设置所有
static void initAll(); static void initAll(bool utf8 = true, bool style = true, int fontSize = 13);
//设置无边框 //设置无边框
static void setFramelessForm(QWidget *widgetMain, bool tool = false, bool top = false, bool menu = true); static void setFramelessForm(QWidget *widgetMain, bool tool = false, bool top = false, bool menu = true);

View File

@ -3,9 +3,13 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
QApplication::setAttribute(Qt::AA_Use96Dpi);
#endif
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0)) #if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor); QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor);
#endif #endif
QApplication a(argc, argv); QApplication a(argc, argv);
a.setWindowIcon(QIcon(":/main.ico")); a.setWindowIcon(QIcon(":/main.ico"));

View File

@ -85,7 +85,7 @@ void AppData::loadIP(QComboBox *cbox)
//获取本机所有IP //获取本机所有IP
static QStringList ips; static QStringList ips;
if (ips.count() == 0) { if (ips.count() == 0) {
#ifdef emsdk #ifdef Q_OS_WASM
ips << "127.0.0.1"; ips << "127.0.0.1";
#else #else
QList<QNetworkInterface> netInterfaces = QNetworkInterface::allInterfaces(); QList<QNetworkInterface> netInterfaces = QNetworkInterface::allInterfaces();

View File

@ -1,5 +1,6 @@
#include "quihelper.h" #include "quihelper.h"
#define TIMEMS qPrintable(QTime::currentTime().toString("HH:mm:ss zzz"))
int QUIHelper::getScreenIndex() int QUIHelper::getScreenIndex()
{ {
//需要对多个屏幕进行处理 //需要对多个屏幕进行处理
@ -57,6 +58,11 @@ int QUIHelper::deskHeight()
return getScreenRect().height(); return getScreenRect().height();
} }
QSize QUIHelper::deskSize()
{
return getScreenRect().size();
}
QWidget *QUIHelper::centerBaseForm = 0; QWidget *QUIHelper::centerBaseForm = 0;
void QUIHelper::setFormInCenter(QWidget *form) void QUIHelper::setFormInCenter(QWidget *form)
{ {
@ -77,6 +83,19 @@ void QUIHelper::setFormInCenter(QWidget *form)
form->move(movePoint); form->move(movePoint);
} }
void QUIHelper::showForm(QWidget *form)
{
setFormInCenter(form);
//判断宽高是否超过了屏幕分辨率,超过了则最大化显示
//qDebug() << TIMEMS << form->size() << deskSize();
if (form->width() + 20 > deskWidth() || form->height() + 50 > deskHeight()) {
form->showMaximized();
} else {
form->show();
}
}
QString QUIHelper::appName() QString QUIHelper::appName()
{ {
//没有必要每次都获取,只有当变量为空时才去获取一次 //没有必要每次都获取,只有当变量为空时才去获取一次
@ -101,12 +120,36 @@ QString QUIHelper::appPath()
#endif #endif
} }
QString QUIHelper::getUuid() QList<QColor> QUIHelper::colors = QList<QColor>();
QList<QColor> QUIHelper::getColorList()
{ {
QString uuid = QUuid::createUuid().toString(); //备用颜色集合 可以自行添加
uuid.replace("{", ""); if (colors.count() == 0) {
uuid.replace("}", ""); colors << QColor(0, 176, 180) << QColor(0, 113, 193) << QColor(255, 192, 0);
return uuid; colors << QColor(72, 103, 149) << QColor(185, 87, 86) << QColor(0, 177, 125);
colors << QColor(214, 77, 84) << QColor(71, 164, 233) << QColor(34, 163, 169);
colors << QColor(59, 123, 156) << QColor(162, 121, 197) << QColor(72, 202, 245);
colors << QColor(0, 150, 121) << QColor(111, 9, 176) << QColor(250, 170, 20);
}
return colors;
}
QStringList QUIHelper::getColorNames()
{
QList<QColor> colors = getColorList();
QStringList colorNames;
foreach (QColor color, colors) {
colorNames << color.name();
}
return colorNames;
}
QColor QUIHelper::getRandColor()
{
QList<QColor> colors = getColorList();
int index = getRandValue(0, colors.count(), true);
return colors.at(index);
} }
void QUIHelper::initRand() void QUIHelper::initRand()
@ -116,6 +159,82 @@ void QUIHelper::initRand()
srand(t.msec() + t.second() * 1000); srand(t.msec() + t.second() * 1000);
} }
float QUIHelper::getRandFloat(float min, float max)
{
double diff = fabs(max - min);
double value = (double)(rand() % 100) / 100;
value = min + value * diff;
return value;
}
double QUIHelper::getRandValue(int min, int max, bool contansMin, bool contansMax)
{
int value;
#if (QT_VERSION <= QT_VERSION_CHECK(5,10,0))
//通用公式 a是起始值,n是整数的范围
//int value = a + rand() % n;
if (contansMin) {
if (contansMax) {
value = min + 0 + (rand() % (max - min + 1));
} else {
value = min + 0 + (rand() % (max - min + 0));
}
} else {
if (contansMax) {
value = min + 1 + (rand() % (max - min + 0));
} else {
value = min + 1 + (rand() % (max - min - 1));
}
}
#else
if (contansMin) {
if (contansMax) {
value = QRandomGenerator::global()->bounded(min + 0, max + 1);
} else {
value = QRandomGenerator::global()->bounded(min + 0, max + 0);
}
} else {
if (contansMax) {
value = QRandomGenerator::global()->bounded(min + 1, max + 1);
} else {
value = QRandomGenerator::global()->bounded(min + 1, max + 0);
}
}
#endif
return value;
}
QStringList QUIHelper::getRandPoint(int count, float mainLng, float mainLat, float dotLng, float dotLat)
{
//随机生成点坐标
QStringList points;
for (int i = 0; i < count; ++i) {
//0.00881415 0.000442928
#if (QT_VERSION >= QT_VERSION_CHECK(5,10,0))
float lngx = QRandomGenerator::global()->bounded(dotLng);
float latx = QRandomGenerator::global()->bounded(dotLat);
#else
float lngx = getRandFloat(dotLng / 10, dotLng);
float latx = getRandFloat(dotLat / 10, dotLat);
#endif
//需要先用精度转换成字符串
QString lng2 = QString::number(mainLng + lngx, 'f', 8);
QString lat2 = QString::number(mainLat + latx, 'f', 8);
QString point = QString("%1,%2").arg(lng2).arg(lat2);
points << point;
}
return points;
}
QString QUIHelper::getUuid()
{
QString uuid = QUuid::createUuid().toString();
uuid.replace("{", "");
uuid.replace("}", "");
return uuid;
}
void QUIHelper::newDir(const QString &dirName) void QUIHelper::newDir(const QString &dirName)
{ {
QString strDir = dirName; QString strDir = dirName;
@ -151,30 +270,68 @@ void QUIHelper::sleep(int msec)
void QUIHelper::setStyle() void QUIHelper::setStyle()
{ {
//打印下所有内置风格的名字 //打印下所有内置风格的名字
qDebug() << "Qt内置的样式" << QStyleFactory::keys(); qDebug() << TIMEMS << "QStyleFactory::keys" << QStyleFactory::keys();
//设置内置风格
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
qApp->setStyle(QStyleFactory::create("Fusion")); qApp->setStyle(QStyleFactory::create("Fusion"));
#else #else
qApp->setStyle(QStyleFactory::create("Cleanlooks")); qApp->setStyle(QStyleFactory::create("Cleanlooks"));
#endif #endif
//qApp->setPalette(QPalette("#FFFFFF"));
//设置指定颜色
QPalette palette;
palette.setBrush(QPalette::Window, QColor("#F0F0F0"));
qApp->setPalette(palette);
}
QFont QUIHelper::addFont(const QString &fontFile, const QString &fontName)
{
//判断图形字体是否存在,不存在则加入
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);
}
}
//再次判断是否包含字体名称防止加载失败
QFont font;
if (fontDb.families().contains(fontName)) {
font = QFont(fontName);
#if (QT_VERSION >= QT_VERSION_CHECK(4,8,0))
font.setHintingPreference(QFont::PreferNoHinting);
#endif
}
return font;
} }
void QUIHelper::setFont(int fontSize) void QUIHelper::setFont(int fontSize)
{ {
QFont font; #ifdef rk3399
font.setFamily("MicroSoft Yahei"); return;
#ifdef Q_OS_ANDROID #endif
font.setPixelSize(15); //网页套件需要主动加载中文字体才能正常显示中文
#elif __arm__ #ifdef Q_OS_WASM
font.setPixelSize(25); QString fontFile = ":/font/DroidSansFallback.ttf";
#else QString fontName = "Droid Sans Fallback";
font.setPixelSize(fontSize); qApp->setFont(addFont(fontFile, fontName));
return;
#endif #endif
#ifndef rk3399 #ifdef __arm__
qApp->setFont(font); fontSize = 25;
#endif #endif
#ifdef Q_OS_ANDROID
fontSize = 15;
#endif
QFont font;
font.setFamily("MicroSoft Yahei");
font.setPixelSize(fontSize);
qApp->setFont(font);
} }
void QUIHelper::setCode(bool utf8) void QUIHelper::setCode(bool utf8)
@ -205,20 +362,23 @@ void QUIHelper::setTranslator(const QString &qmFile)
} }
QTranslator *translator = new QTranslator(qApp); QTranslator *translator = new QTranslator(qApp);
translator->load(qmFile); if (translator->load(qmFile)) {
qApp->installTranslator(translator); qApp->installTranslator(translator);
}
} }
void QUIHelper::initAll() void QUIHelper::initAll(bool utf8, bool style, int fontSize)
{ {
//初始化随机数种子 //初始化随机数种子
QUIHelper::initRand(); QUIHelper::initRand();
//设置样式风格
QUIHelper::setStyle();
//设置字体
QUIHelper::setFont(13);
//设置编码 //设置编码
QUIHelper::setCode(); QUIHelper::setCode(utf8);
//设置样式风格
if (style) {
QUIHelper::setStyle();
}
//设置字体
QUIHelper::setFont(fontSize);
//设置翻译文件支持多个 //设置翻译文件支持多个
QUIHelper::setTranslator(":/qm/widgets.qm"); QUIHelper::setTranslator(":/qm/widgets.qm");
QUIHelper::setTranslator(":/qm/qt_zh_CN.qm"); QUIHelper::setTranslator(":/qm/qt_zh_CN.qm");
@ -299,7 +459,12 @@ QString QUIHelper::getXorEncryptDecrypt(const QString &value, char key)
key = 127; key = 127;
} }
//大概从5.9版本输出的加密密码字符串前面会加上 @String 字符
QString result = value; QString result = value;
if (result.startsWith("@String")) {
result = result.mid(8, result.length() - 9);
}
int count = result.count(); int count = result.count();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
result[i] = QChar(result.at(i).toLatin1() ^ key); result[i] = QChar(result.at(i).toLatin1() ^ key);
@ -331,6 +496,8 @@ uchar QUIHelper::getCheckCode(const QByteArray &data)
void QUIHelper::initTableView(QTableView *tableView, int rowHeight, bool headVisible, bool edit, bool stretchLast) void QUIHelper::initTableView(QTableView *tableView, int rowHeight, bool headVisible, bool edit, bool stretchLast)
{ {
//设置弱属性用于应用qss特殊样式
tableView->setProperty("model", true);
//取消自动换行 //取消自动换行
tableView->setWordWrap(false); tableView->setWordWrap(false);
//超出文本不显示省略号 //超出文本不显示省略号
@ -374,7 +541,8 @@ void QUIHelper::openFile(const QString &fileName, const QString &msg)
#ifdef __arm__ #ifdef __arm__
return; return;
#endif #endif
if (fileName.isEmpty()) { //文件不存在则不用处理
if (!QFile(fileName).exists()) {
return; return;
} }
if (QUIHelper::showMessageBoxQuestion(msg + "成功!确定现在就打开吗?") == QMessageBox::Yes) { if (QUIHelper::showMessageBoxQuestion(msg + "成功!确定现在就打开吗?") == QMessageBox::Yes) {
@ -401,8 +569,10 @@ bool QUIHelper::checkIniFile(const QString &iniFile)
QStringList list = line.split("="); QStringList list = line.split("=");
if (list.count() == 2) { if (list.count() == 2) {
if (list.at(1) == "") { QString key = list.at(0);
qDebug() << "ini node no value" << list.at(0); QString value = list.at(1);
if (value.isEmpty()) {
qDebug() << TIMEMS << "ini node no value" << key;
ok = false; ok = false;
break; break;
} }

View File

@ -13,29 +13,52 @@ public:
//获取桌面宽度高度+居中显示 //获取桌面宽度高度+居中显示
static int deskWidth(); static int deskWidth();
static int deskHeight(); static int deskHeight();
static QSize deskSize();
//居中显示窗体 //居中显示窗体
//定义标志位指定是以桌面为参照还是主程序界面为参照 //定义标志位指定是以桌面为参照还是主程序界面为参照
static QWidget *centerBaseForm; static QWidget *centerBaseForm;
static void setFormInCenter(QWidget *form); static void setFormInCenter(QWidget *form);
static void showForm(QWidget *form);
//程序文件名称+当前所在路径 //程序文件名称+当前所在路径
static QString appName(); static QString appName();
static QString appPath(); static QString appPath();
//获取uuid+初始化随机数种子+新建目录+延时 //获取内置颜色集合
static QString getUuid(); static QList<QColor> colors;
static QList<QColor> getColorList();
static QStringList getColorNames();
//随机获取颜色集合中的颜色
static QColor getRandColor();
//初始化随机数种子
static void initRand(); static void initRand();
//获取随机小数
static float getRandFloat(float min, float max);
//获取随机数,指定最小值和最大值
static double getRandValue(int min, int max, bool contansMin = false, bool contansMax = false);
//获取范围值随机经纬度集合
static QStringList getRandPoint(int count, float mainLng, float mainLat, float dotLng, float dotLat);
//获取uuid
static QString getUuid();
//可执行文件目录下新建目录
static void newDir(const QString &dirName); static void newDir(const QString &dirName);
//延时
static void sleep(int msec); static void sleep(int msec);
//设置样式+字体+编码+居中+翻译 //设置Qt自带样式
static void setStyle(); static void setStyle();
//设置字体
static QFont addFont(const QString &fontFile, const QString &fontName);
static void setFont(int fontSize = 12); static void setFont(int fontSize = 12);
//设置编码
static void setCode(bool utf8 = true); static void setCode(bool utf8 = true);
//设置翻译文件
static void setTranslator(const QString &qmFile); static void setTranslator(const QString &qmFile);
//一次性设置所有 //一次性设置所有
static void initAll(); static void initAll(bool utf8 = true, bool style = true, int fontSize = 13);
//设置无边框 //设置无边框
static void setFramelessForm(QWidget *widgetMain, bool tool = false, bool top = false, bool menu = true); static void setFramelessForm(QWidget *widgetMain, bool tool = false, bool top = false, bool menu = true);

View File

@ -33,7 +33,7 @@ void frmMain::initForm()
ui->tabWidget->addTab(new frmWebClient, "WEB客户端"); ui->tabWidget->addTab(new frmWebClient, "WEB客户端");
ui->tabWidget->addTab(new frmWebServer, "WEB服务端"); ui->tabWidget->addTab(new frmWebServer, "WEB服务端");
#endif #endif
#ifdef emsdk #ifdef Q_OS_WASM
AppConfig::CurrentIndex = 4; AppConfig::CurrentIndex = 4;
#endif #endif
} }

View File

@ -212,6 +212,8 @@ void frmTcpServer::on_btnListen_clicked()
if (isOk) { if (isOk) {
append(0, "监听成功"); append(0, "监听成功");
ui->btnListen->setText("关闭"); ui->btnListen->setText("关闭");
} else {
append(2, QString("监听失败: %1").arg(server->errorString()));
} }
} else { } else {
isOk = false; isOk = false;

View File

@ -242,8 +242,10 @@ void frmUdpServer::on_btnListen_clicked()
if (ui->btnListen->text() == "监听") { if (ui->btnListen->text() == "监听") {
bool ok = socket->bind(QHostAddress(AppConfig::UdpListenIP), AppConfig::UdpListenPort); bool ok = socket->bind(QHostAddress(AppConfig::UdpListenIP), AppConfig::UdpListenPort);
if (ok) { if (ok) {
ui->btnListen->setText("关闭");
append(0, "监听成功"); append(0, "监听成功");
ui->btnListen->setText("关闭");
} else {
append(2, QString("监听失败: %1").arg(socket->errorString()));
} }
} else { } else {
socket->abort(); socket->abort();

View File

@ -210,6 +210,8 @@ void frmWebServer::on_btnListen_clicked()
if (isOk) { if (isOk) {
append(0, "监听成功"); append(0, "监听成功");
ui->btnListen->setText("关闭"); ui->btnListen->setText("关闭");
} else {
append(2, QString("监听失败: %1").arg(server->errorString()));
} }
} else { } else {
isOk = false; isOk = false;

View File

@ -3,9 +3,13 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
QApplication::setAttribute(Qt::AA_Use96Dpi);
#endif
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0)) #if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor); QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor);
#endif #endif
QApplication a(argc, argv); QApplication a(argc, argv);
a.setWindowIcon(QIcon(":/main.ico")); a.setWindowIcon(QIcon(":/main.ico"));

View File

@ -13,7 +13,6 @@ TARGET = nettool
TEMPLATE = app TEMPLATE = app
RC_FILE = qrc/main.rc RC_FILE = qrc/main.rc
wasm { wasm {
DEFINES += emsdk
RESOURCES += qrc/font.qrc RESOURCES += qrc/font.qrc
} else { } else {
DESTDIR = $$PWD/../bin DESTDIR = $$PWD/../bin

View File

@ -1,5 +1,5 @@
<RCC> <RCC>
<qresource prefix="/"> <qresource prefix="/">
<file>DroidSansFallback.ttf</file> <file>font/DroidSansFallback.ttf</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@ -7,7 +7,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -7,7 +7,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -11,7 +11,10 @@ int main(int argc, char *argv[])
//设置高分屏缩放舍入策略 //设置高分屏缩放舍入策略
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor); QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor);
#endif #endif
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -13,10 +13,9 @@ int main(int argc, char *argv[])
#endif #endif
QApplication a(argc, argv); QApplication a(argc, argv);
//a.setFont(QFont("Microsoft Yahei", 9));
QFont font; QFont font;
font.setFamily("Microsoft Yahei"); font.setFamily("Microsoft Yahei");
font.setPixelSize(12); font.setPixelSize(13);
a.setFont(font); a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))

View File

@ -40,11 +40,14 @@ void frmMain::initForm()
ui->widgetTitle->installEventFilter(this); ui->widgetTitle->installEventFilter(this);
ui->widgetTitle->setProperty("form", "title"); ui->widgetTitle->setProperty("form", "title");
ui->widgetTop->setProperty("nav", "top"); ui->widgetTop->setProperty("nav", "top");
QFont font;
font.setPixelSize(25);
ui->labTitle->setFont(font);
ui->labTitle->setText("智能访客管理平台"); ui->labTitle->setText("智能访客管理平台");
ui->labTitle->setFont(QFont("Microsoft Yahei", 20));
this->setWindowTitle(ui->labTitle->text()); this->setWindowTitle(ui->labTitle->text());
ui->stackedWidget->setStyleSheet("QLabel{font:60pt;}"); ui->stackedWidget->setStyleSheet("QLabel{font:60px;}");
//单独设置指示器大小 //单独设置指示器大小
int addWidth = 20; int addWidth = 20;
@ -55,22 +58,21 @@ void frmMain::initForm()
int borderWidth = 3; int borderWidth = 3;
QStringList qss; QStringList qss;
qss.append(QString("QComboBox::drop-down,QDateEdit::drop-down,QTimeEdit::drop-down,QDateTimeEdit::drop-down{width:%1px;}").arg(addWidth)); qss << QString("QComboBox::drop-down,QDateEdit::drop-down,QTimeEdit::drop-down,QDateTimeEdit::drop-down{width:%1px;}").arg(addWidth);
qss.append(QString("QComboBox::down-arrow,QDateEdit[calendarPopup=\"true\"]::down-arrow,QTimeEdit[calendarPopup=\"true\"]::down-arrow," qss << QString("QComboBox::down-arrow,QDateEdit[calendarPopup=\"true\"]::down-arrow,QTimeEdit[calendarPopup=\"true\"]::down-arrow,"
"QDateTimeEdit[calendarPopup=\"true\"]::down-arrow{width:%1px;height:%1px;right:2px;}").arg(addHeight)); "QDateTimeEdit[calendarPopup=\"true\"]::down-arrow{width:%1px;height:%1px;right:2px;}").arg(addHeight);
qss.append(QString("QRadioButton::indicator{width:%1px;height:%1px;}").arg(rbtnWidth)); qss << QString("QRadioButton::indicator{width:%1px;height:%1px;}").arg(rbtnWidth);
qss.append(QString("QCheckBox::indicator,QGroupBox::indicator,QTreeWidget::indicator,QListWidget::indicator{width:%1px;height:%1px;}").arg(ckWidth)); qss << QString("QCheckBox::indicator,QGroupBox::indicator,QTreeWidget::indicator,QListWidget::indicator{width:%1px;height:%1px;}").arg(ckWidth);
qss.append(QString("QScrollBar:horizontal{min-height:%1px;border-radius:%2px;}QScrollBar::handle:horizontal{border-radius:%2px;}" qss << QString("QScrollBar:horizontal{min-height:%1px;border-radius:%2px;}QScrollBar::handle:horizontal{border-radius:%2px;}"
"QScrollBar:vertical{min-width:%1px;border-radius:%2px;}QScrollBar::handle:vertical{border-radius:%2px;}").arg(scrWidth).arg(scrWidth / 2)); "QScrollBar:vertical{min-width:%1px;border-radius:%2px;}QScrollBar::handle:vertical{border-radius:%2px;}").arg(scrWidth).arg(scrWidth / 2);
qss.append(QString("QWidget#widget_top>QToolButton:pressed,QWidget#widget_top>QToolButton:hover," qss << QString("QWidget#widget_top>QToolButton:pressed,QWidget#widget_top>QToolButton:hover,"
"QWidget#widget_top>QToolButton:checked,QWidget#widget_top>QLabel:hover{" "QWidget#widget_top>QToolButton:checked,QWidget#widget_top>QLabel:hover{"
"border-width:0px 0px %1px 0px;}").arg(borderWidth)); "border-width:0px 0px %1px 0px;}").arg(borderWidth);
qss.append(QString("QWidget#widgetleft>QPushButton:checked,QWidget#widgetleft>QToolButton:checked," qss << QString("QWidget#widgetleft>QPushButton:checked,QWidget#widgetleft>QToolButton:checked,"
"QWidget#widgetleft>QPushButton:pressed,QWidget#widgetleft>QToolButton:pressed{" "QWidget#widgetleft>QPushButton:pressed,QWidget#widgetleft>QToolButton:pressed{"
"border-width:0px 0px 0px %1px;}").arg(borderWidth)); "border-width:0px 0px 0px %1px;}").arg(borderWidth);
this->setStyleSheet(qss.join("")); this->setStyleSheet(qss.join(""));
QSize icoSize(32, 32); QSize icoSize(32, 32);
int icoWidth = 85; int icoWidth = 85;

View File

@ -6,9 +6,13 @@ int main(int argc, char *argv[])
{ {
//设置不应用操作系统设置比如字体 //设置不应用操作系统设置比如字体
QApplication::setDesktopSettingsAware(false); QApplication::setDesktopSettingsAware(false);
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0)) #if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor); QApplication::setAttribute(Qt::AA_Use96Dpi);
#endif #endif
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor);
#endif
QApplication a(argc, argv); QApplication a(argc, argv);
AppInit::Instance()->start(); AppInit::Instance()->start();
@ -26,6 +30,7 @@ int main(int argc, char *argv[])
} }
frmMain w; frmMain w;
w.resize(800, 600);
QUIHelper::setFormInCenter(&w); QUIHelper::setFormInCenter(&w);
w.show(); w.show();

View File

@ -66,13 +66,15 @@ void frmMain::initForm()
ui->widgetTitle->setProperty("form", "title"); ui->widgetTitle->setProperty("form", "title");
//关联事件过滤器用于双击放大 //关联事件过滤器用于双击放大
ui->widgetTitle->installEventFilter(this); ui->widgetTitle->installEventFilter(this);
ui->widgetTop->setProperty("nav", "top"); ui->widgetTop->setProperty("nav", "top");
QFont font;
font.setPixelSize(25);
ui->labTitle->setFont(font);
ui->labTitle->setText("智能访客管理平台"); ui->labTitle->setText("智能访客管理平台");
ui->labTitle->setFont(QFont("Microsoft Yahei", 20));
this->setWindowTitle(ui->labTitle->text()); this->setWindowTitle(ui->labTitle->text());
ui->stackedWidget->setStyleSheet("QLabel{font:60pt;}"); ui->stackedWidget->setStyleSheet("QLabel{font:60px;}");
QSize icoSize(32, 32); QSize icoSize(32, 32);
int icoWidth = 85; int icoWidth = 85;

View File

@ -6,8 +6,11 @@ int main(int argc, char *argv[])
{ {
//设置不应用操作系统设置比如字体 //设置不应用操作系统设置比如字体
QApplication::setDesktopSettingsAware(false); QApplication::setDesktopSettingsAware(false);
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
QApplication::setAttribute(Qt::AA_Use96Dpi);
#endif
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0)) #if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor); QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor);
#endif #endif
QApplication a(argc, argv); QApplication a(argc, argv);
AppInit::Instance()->start(); AppInit::Instance()->start();

View File

@ -6,8 +6,11 @@ int main(int argc, char *argv[])
{ {
//设置不应用操作系统设置比如字体 //设置不应用操作系统设置比如字体
QApplication::setDesktopSettingsAware(false); QApplication::setDesktopSettingsAware(false);
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
QApplication::setAttribute(Qt::AA_Use96Dpi);
#endif
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0)) #if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor); QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor);
#endif #endif
QApplication a(argc, argv); QApplication a(argc, argv);
AppInit::Instance()->start(); AppInit::Instance()->start();

View File

@ -6,8 +6,11 @@ int main(int argc, char *argv[])
{ {
//设置不应用操作系统设置比如字体 //设置不应用操作系统设置比如字体
QApplication::setDesktopSettingsAware(false); QApplication::setDesktopSettingsAware(false);
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
QApplication::setAttribute(Qt::AA_Use96Dpi);
#endif
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0)) #if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor); QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor);
#endif #endif
QApplication a(argc, argv); QApplication a(argc, argv);
AppInit::Instance()->start(); AppInit::Instance()->start();

View File

@ -9,7 +9,10 @@ int main(int argc, char *argv[])
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif #endif
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -6,7 +6,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -6,7 +6,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -7,7 +7,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -7,7 +7,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -81,6 +81,7 @@ void VideoPanel::initForm()
widget->installEventFilter(this); widget->installEventFilter(this);
widget->setFocusPolicy(Qt::StrongFocus); widget->setFocusPolicy(Qt::StrongFocus);
widget->setAlignment(Qt::AlignCenter); widget->setAlignment(Qt::AlignCenter);
widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
//二选一可以选择显示文字,也可以选择显示背景图片 //二选一可以选择显示文字,也可以选择显示背景图片
widget->setText(QString("通道 %1").arg(i + 1)); widget->setText(QString("通道 %1").arg(i + 1));

View File

@ -7,7 +7,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -7,7 +7,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -10,7 +10,10 @@ int main(int argc, char *argv[])
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor); QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor);
#endif #endif
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -12,7 +12,10 @@ int main(int argc, char *argv[])
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor); QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor);
#endif #endif
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
a.setWindowIcon(QIcon(":/image/gifwidget.ico")); a.setWindowIcon(QIcon(":/image/gifwidget.ico"));
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))

View File

@ -7,7 +7,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -7,7 +7,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -7,7 +7,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -11,7 +11,10 @@ int main(int argc, char *argv[])
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor); QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor);
#endif #endif
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); QFont font;
font.setFamily("Microsoft Yahei");
font.setPixelSize(13);
a.setFont(font);
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
#if _MSC_VER #if _MSC_VER

View File

@ -6,3 +6,10 @@ SUBDIRS += lunarcalendarwidget
SUBDIRS += maskwidget SUBDIRS += maskwidget
SUBDIRS += movewidget SUBDIRS += movewidget
SUBDIRS += screenwidget SUBDIRS += screenwidget
#Qt6有些项目还不支持
greaterThan(QT_MAJOR_VERSION, 5) {
msvc {
SUBDIRS -= lunarcalendarwidget
}
}