77 lines
2.2 KiB
C++
77 lines
2.2 KiB
C++
|
|
#include "qtcommonclass.h"
|
|||
|
|
#include <QUuid>
|
|||
|
|
#include <QCoreApplication>
|
|||
|
|
#include <QFile>
|
|||
|
|
#include <QMessageBox>
|
|||
|
|
#include <QSettings>
|
|||
|
|
#include <QPainter>
|
|||
|
|
|
|||
|
|
QtCommonClass::QtCommonClass(QObject *parent)
|
|||
|
|
: QObject(parent)
|
|||
|
|
{}
|
|||
|
|
|
|||
|
|
QtCommonClass::~QtCommonClass()
|
|||
|
|
{}
|
|||
|
|
|
|||
|
|
QString QtCommonClass::getUUid()
|
|||
|
|
{
|
|||
|
|
QUuid id = QUuid::createUuid();
|
|||
|
|
QString strId = id.toString();
|
|||
|
|
strId.replace("{", "");
|
|||
|
|
strId.replace("}", "");
|
|||
|
|
strId.replace("-", "");
|
|||
|
|
//qDebug() << strId;
|
|||
|
|
return strId;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//读取
|
|||
|
|
double QtCommonClass::readConfigSize(QString filePathName, int &iIndex, int &iNum, int &iOneWidth, int &iHeadHigh, int &iTitleHigh, int &iCurveHigh, int &iMove, int &iPointNum, int &iLineNum)
|
|||
|
|
{
|
|||
|
|
QSettings set(filePathName, QSettings::IniFormat);
|
|||
|
|
set.beginGroup("config");
|
|||
|
|
iIndex = set.value("iIndex", "0").toInt();
|
|||
|
|
iNum = set.value("iNum", "0").toInt();
|
|||
|
|
iOneWidth = set.value("iOneWidth", "200").toInt();
|
|||
|
|
//
|
|||
|
|
iHeadHigh = set.value("iHeadHigh", "30").toInt();
|
|||
|
|
iTitleHigh = set.value("iTitleHigh", "303").toInt();
|
|||
|
|
iCurveHigh = set.value("iCurveHigh", "3020").toInt();
|
|||
|
|
//
|
|||
|
|
iMove = set.value("iMove", "12").toInt();
|
|||
|
|
iPointNum = set.value("iPointNum", "30000").toInt();
|
|||
|
|
iLineNum = set.value("iLineNum", "0").toInt();
|
|||
|
|
|
|||
|
|
set.endGroup();
|
|||
|
|
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
double QtCommonClass::readXyRange(QString filePathName, int &iX1, int &iX2, int &iY1, int &iY2)
|
|||
|
|
{
|
|||
|
|
QSettings set(filePathName, QSettings::IniFormat);
|
|||
|
|
set.beginGroup("range");
|
|||
|
|
iX1 = set.value("iX1", "-15").toInt();
|
|||
|
|
iX2 = set.value("iX2", "15").toInt();
|
|||
|
|
iY1 = set.value("iY1", "-3000").toInt();
|
|||
|
|
iY2 = set.value("iY2", "0").toInt();
|
|||
|
|
set.endGroup();
|
|||
|
|
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
void QtCommonClass::setButtonIconWithText(QPushButton *button, const QString &imagePath, const QString &text, const QFont &font, const QColor &textColor)
|
|||
|
|
{
|
|||
|
|
QPixmap pixmap(imagePath);
|
|||
|
|
QPainter painter(&pixmap);
|
|||
|
|
painter.setFont(font);
|
|||
|
|
painter.setPen(textColor);
|
|||
|
|
painter.drawText(pixmap.rect(), Qt::AlignCenter, text);
|
|||
|
|
painter.end();
|
|||
|
|
|
|||
|
|
button->setIcon(pixmap);
|
|||
|
|
button->setIconSize(pixmap.size());
|
|||
|
|
button->setFlat(true);//就是这句能够实现按钮透明,用png图片时很有用
|
|||
|
|
button->setStyleSheet("border: 0px");//消除边框,取消点击效果
|
|||
|
|
}
|