改进代码
parent
fdcaff2b21
commit
abc123dc7e
|
@ -12,10 +12,9 @@ int main(int argc, char *argv[])
|
|||
a.setFont(font);
|
||||
|
||||
//设置编码以及加载中文翻译文件
|
||||
QUIHelper::setCode();
|
||||
QUIHelper::setTranslator(":/qt_zh_CN.qm");
|
||||
QUIHelper::setTranslator(":/widgets.qm");
|
||||
QUIHelper::initRand();
|
||||
QUIHelper::setCode();
|
||||
QUIHelper::setTranslator();
|
||||
|
||||
AppConfig::ConfigFile = QString("%1/%2.ini").arg(QUIHelper::appPath()).arg(QUIHelper::appName());
|
||||
AppConfig::readConfig();
|
||||
|
|
|
@ -57,7 +57,9 @@ public:
|
|||
QString getEndDateTime() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
//设置左上角图标
|
||||
void setIconMain(int icon, quint32 size = 12);
|
||||
//设置日期格式
|
||||
void setFormat(const QString &format);
|
||||
};
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef QUIHEAD_H
|
||||
#define QUIHEAD_H
|
||||
|
||||
//日期时间字符串宏定义
|
||||
#ifndef TIMEMS
|
||||
#define TIMEMS qPrintable(QTime::currentTime().toString("HH:mm:ss zzz"))
|
||||
#endif
|
||||
|
|
|
@ -190,8 +190,21 @@ void QUIHelper::setFont(const QString &ttfFile, const QString &fontName, int fon
|
|||
qApp->setFont(font);
|
||||
}
|
||||
|
||||
void QUIHelper::setTranslator()
|
||||
{
|
||||
//以后还有其他的自行加上去就行
|
||||
QUIHelper::setTranslator(":/qm/widgets.qm");
|
||||
QUIHelper::setTranslator(":/qm/qt_zh_CN.qm");
|
||||
QUIHelper::setTranslator(":/qm/designer_zh_CN.qm");
|
||||
}
|
||||
|
||||
void QUIHelper::setTranslator(const QString &qmFile)
|
||||
{
|
||||
//过滤下不存在的就不用设置了
|
||||
if (!QFile(qmFile).exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QTranslator *translator = new QTranslator(qApp);
|
||||
translator->load(qmFile);
|
||||
qApp->installTranslator(translator);
|
||||
|
@ -310,8 +323,13 @@ void QUIHelper::setFormShadow(QWidget *widget, QLayout *layout, const QString &c
|
|||
return;
|
||||
}
|
||||
|
||||
//先判断是否已经存在阴影效果
|
||||
QGraphicsDropShadowEffect *shadowEffect = (QGraphicsDropShadowEffect *)widget->graphicsEffect();
|
||||
if (shadowEffect == 0) {
|
||||
shadowEffect = new QGraphicsDropShadowEffect(widget);
|
||||
}
|
||||
|
||||
//采用系统自带的函数设置阴影
|
||||
QGraphicsDropShadowEffect *shadowEffect = new QGraphicsDropShadowEffect(widget);
|
||||
shadowEffect->setOffset(0, 0);
|
||||
shadowEffect->setColor(color);
|
||||
shadowEffect->setBlurRadius(radius);
|
||||
|
@ -1316,7 +1334,8 @@ int QUIHelper::showMessageBoxQuestion(const QString &info)
|
|||
{
|
||||
if (isCustomUI) {
|
||||
QUIMessageBox msg;
|
||||
msg.setMessage(info, 1);msg.update();
|
||||
msg.setMessage(info, 1);
|
||||
msg.update();
|
||||
return msg.exec();
|
||||
} else {
|
||||
QMessageBox box(QMessageBox::Question, "询问", info);
|
||||
|
@ -1492,6 +1511,8 @@ void QUIHelper::setLogo(QLabel *label, const QString &file,
|
|||
text.replace(oldColor, newColor);
|
||||
f.close();
|
||||
|
||||
//目录不存在则新建
|
||||
QUIHelper::newDir("logo");
|
||||
//打开新的文件输出
|
||||
fileName = QString("%1/logo/temp.svg").arg(QUIHelper::appPath());
|
||||
QFile f2(fileName);
|
||||
|
|
|
@ -35,7 +35,8 @@ public:
|
|||
static void setFont(const QString &ttfFile = ":/font/DroidSansFallback.ttf",
|
||||
const QString &fontName = "Microsoft Yahei", int fontSize = 12);
|
||||
//设置翻译文件
|
||||
static void setTranslator(const QString &qmFile = ":/qm/qt_zh_CN.qm");
|
||||
static void setTranslator();
|
||||
static void setTranslator(const QString &qmFile);
|
||||
|
||||
//初始化数据库
|
||||
static void initDb(const QString &dbName);
|
||||
|
|
|
@ -59,7 +59,9 @@ public:
|
|||
QString getValue()const;
|
||||
|
||||
public Q_SLOTS:
|
||||
//设置左上角图标
|
||||
void setIconMain(int icon, quint32 size = 12);
|
||||
//设置输入对话框的各种参数
|
||||
void setParameter(const QString &title, int type = 0, int closeSec = 0,
|
||||
QString placeholderText = QString(), bool pwd = false,
|
||||
const QString &defaultValue = QString());
|
||||
|
|
|
@ -31,6 +31,7 @@ void QUIMessageBox::showEvent(QShowEvent *)
|
|||
QUIHelper::setIconBtn(btnCancel, ":/image/btn_close.png", 0xf00d);
|
||||
QUIHelper::setFormInCenter(this);
|
||||
this->activateWindow();
|
||||
//QMetaObject::invokeMethod(this, "autoSize", Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void QUIMessageBox::closeEvent(QCloseEvent *)
|
||||
|
@ -305,7 +306,12 @@ void QUIMessageBox::setMessage(const QString &msg, int type, int closeSec)
|
|||
|
||||
this->labInfo->setText(msg);
|
||||
this->setWindowTitle(this->labTitle->text());
|
||||
this->autoSize();
|
||||
}
|
||||
|
||||
void QUIMessageBox::autoSize()
|
||||
{
|
||||
QString msg = labInfo->text();
|
||||
//长度符合要求比如就两行只需要默认尺寸
|
||||
bool normal = (msg.length() < 30);
|
||||
//计算有多少个换行符
|
||||
|
@ -322,10 +328,10 @@ void QUIMessageBox::setMessage(const QString &msg, int type, int closeSec)
|
|||
|
||||
//设置对话框的大小总以最合适的大小显示
|
||||
if (normal) {
|
||||
this->layout()->setSizeConstraint(QLayout::SetMinimumSize);
|
||||
this->setFixedSize(QUIDialogMinWidth, QUIDialogMinHeight);
|
||||
//this->layout()->setSizeConstraint(QLayout::SetMinimumSize);
|
||||
this->setFixedSize(QUIDialogMinWidth + 1, QUIDialogMinHeight + 1);
|
||||
} else {
|
||||
this->layout()->setSizeConstraint(QLayout::SetFixedSize);
|
||||
//this->setFixedSize(labInfo->sizeHint() + QSize(100, 120));
|
||||
//this->layout()->setSizeConstraint(QLayout::SetFixedSize);
|
||||
this->setFixedSize(labInfo->sizeHint() + QSize(100, 120));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,9 +56,14 @@ private slots:
|
|||
void on_btnMenu_Close_clicked();
|
||||
|
||||
public Q_SLOTS:
|
||||
//设置左上角图标
|
||||
void setIconMain(int icon, quint32 size = 12);
|
||||
//设置消息图标 图形字体+图片两种方式
|
||||
void setIconMsg(const QString &png, int icon);
|
||||
//设置提示信息带类型和关闭倒计时
|
||||
void setMessage(const QString &msg, int type, int closeSec = 0);
|
||||
//自适应尺寸
|
||||
void autoSize();
|
||||
};
|
||||
|
||||
#endif // QUIMESSAGEBOX_H
|
||||
|
|
|
@ -68,8 +68,14 @@ void QUIStyle::setStyle(const QString &qss)
|
|||
list << "QTabBar::tab:right:selected,QTabBar::tab:right:hover{border-width:0px 2px 0px 0px;}";
|
||||
#endif
|
||||
|
||||
//5.2开始颜色支持透明度
|
||||
QString txtReadOnlyColor = QUIConfig::NormalColorStart.right(6);
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5,2,0))
|
||||
txtReadOnlyColor = "88" + txtReadOnlyColor;
|
||||
#endif
|
||||
|
||||
//增加文本框只读背景颜色
|
||||
list << QString("QLineEdit:read-only{background-color:#88%1;}").arg(QUIConfig::NormalColorStart.right(6));
|
||||
list << QString("QLineEdit:read-only{background-color:#%1;}").arg(txtReadOnlyColor);
|
||||
|
||||
QUIHelper::isCustomUI = true;
|
||||
//阴影边框和配色方案自动变化
|
||||
|
|
|
@ -175,7 +175,7 @@ void QUITipBox::initForm()
|
|||
this->labInfo->setFont(font);
|
||||
|
||||
//显示和隐藏窗体动画效果
|
||||
animation = new QPropertyAnimation(this, "pos");
|
||||
animation = new QPropertyAnimation(this, "pos", this);
|
||||
animation->setDuration(500);
|
||||
animation->setEasingCurve(QEasingCurve::InOutQuad);
|
||||
}
|
||||
|
|
|
@ -49,8 +49,11 @@ private slots:
|
|||
void on_btnMenu_Close_clicked();
|
||||
|
||||
public Q_SLOTS:
|
||||
//设置左上角图标
|
||||
void setIconMain(int icon, quint32 size = 12);
|
||||
//设置提示信息
|
||||
void setTip(const QString &title, const QString &tip, bool fullScreen = false, bool center = true, int closeSec = 0);
|
||||
//隐藏界面
|
||||
void hide();
|
||||
};
|
||||
|
||||
|
|
|
@ -7,7 +7,11 @@ TcpClient1::TcpClient1(QObject *parent) : QTcpSocket(parent)
|
|||
port = 6907;
|
||||
deviceID = "SSJC00000001";
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
|
||||
connect(this, SIGNAL(errorOccurred(QAbstractSocket::SocketError)), this, SLOT(deleteLater()));
|
||||
#else
|
||||
connect(this, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(deleteLater()));
|
||||
#endif
|
||||
connect(this, SIGNAL(disconnected()), this, SLOT(deleteLater()));
|
||||
connect(this, SIGNAL(readyRead()), this, SLOT(readData()));
|
||||
}
|
||||
|
@ -142,10 +146,10 @@ bool TcpServer1::writeData(const QString &deviceID, const QString &data)
|
|||
bool ok = false;
|
||||
foreach (TcpClient1 *client, clients) {
|
||||
if (client->getDeviceID() == deviceID) {
|
||||
client->sendData(data);
|
||||
ok = true;
|
||||
client->sendData(data);
|
||||
ok = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,11 @@ TcpClient2::TcpClient2(QObject *parent) : QTcpSocket(parent)
|
|||
port = 6908;
|
||||
deviceID = "SSJC00000001";
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
|
||||
connect(this, SIGNAL(errorOccurred(QAbstractSocket::SocketError)), this, SLOT(deleteLater()));
|
||||
#else
|
||||
connect(this, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(deleteLater()));
|
||||
#endif
|
||||
connect(this, SIGNAL(disconnected()), this, SLOT(deleteLater()));
|
||||
connect(this, SIGNAL(readyRead()), this, SLOT(readData()));
|
||||
}
|
||||
|
|
|
@ -12,10 +12,9 @@ int main(int argc, char *argv[])
|
|||
a.setFont(font);
|
||||
|
||||
//设置编码以及加载中文翻译文件
|
||||
QUIHelper::setCode();
|
||||
QUIHelper::setTranslator(":/qt_zh_CN.qm");
|
||||
QUIHelper::setTranslator(":/widgets.qm");
|
||||
QUIHelper::initRand();
|
||||
QUIHelper::setCode();
|
||||
QUIHelper::setTranslator();
|
||||
|
||||
AppConfig::ConfigFile = QString("%1/%2.ini").arg(QUIHelper::appPath()).arg(QUIHelper::appName());
|
||||
AppConfig::readConfig();
|
||||
|
|
|
@ -7,11 +7,10 @@ int main(int argc, char *argv[])
|
|||
a.setWindowIcon(QIcon(":/main.ico"));
|
||||
|
||||
//设置编码+字体+中文翻译文件
|
||||
QUIHelper::initRand();
|
||||
QUIHelper::setCode();
|
||||
QUIHelper::setFont(":/DroidSansFallback.ttf");
|
||||
QUIHelper::setTranslator(":/qt_zh_CN.qm");
|
||||
QUIHelper::setTranslator(":/widgets.qm");
|
||||
QUIHelper::initRand();
|
||||
QUIHelper::setTranslator();
|
||||
|
||||
AppConfig::ConfigFile = QString("%1/%2.ini").arg(QUIHelper::appPath()).arg(QUIHelper::appName());
|
||||
AppConfig::readConfig();
|
||||
|
|
Loading…
Reference in New Issue