#include "qtcommonclass.h" #include #include #include #include #include #include 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; } //读取,MyCustom界面高度 double QtCommonClass::readHeight(QString filePathName, int &iHeight) { QSettings set(filePathName, QSettings::IniFormat); set.beginGroup("config"); iHeight = set.value("iHeight", "1").toInt(); set.endGroup(); return 0; } //读取,是否隐藏刻度 double QtCommonClass::readShowScale(QString filePathName, int &iShow) { QSettings set(filePathName, QSettings::IniFormat); set.beginGroup("config"); iShow = set.value("iShow", "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");//消除边框,取消点击效果 }