Browse Source

MODIFY:增加double数据的显示格式和精度设置

master
tianzhendong 11 months ago
parent
commit
c567fc1e66
  1. 12
      numkeydia.cpp
  2. 2
      numkeydia.h

12
numkeydia.cpp

@ -96,6 +96,12 @@ void NumKeyDia::setPLineEdit(QLineEdit *newPLineEdit)
m_isDouble = m_pLineEdit->property("IsDouble").toBool(); m_isDouble = m_pLineEdit->property("IsDouble").toBool();
if(m_isDouble)
{
m_format = m_pLineEdit->property("Format").toInt();
m_prec = m_pLineEdit->property("Prec").toInt();
}
if(m_minValue == m_maxValue) if(m_minValue == m_maxValue)
{ {
ui->label_min->setText(tr("no limit")); ui->label_min->setText(tr("no limit"));
@ -105,8 +111,8 @@ void NumKeyDia::setPLineEdit(QLineEdit *newPLineEdit)
{ {
if(m_isDouble) if(m_isDouble)
{ {
ui->label_max->setText(QString::number(m_maxValue, 10, 3)); ui->label_max->setText(QString::number(m_maxValue, m_format, m_prec));
ui->label_min->setText(QString::number(m_minValue, 10, 3)); ui->label_min->setText(QString::number(m_minValue, m_format, m_prec));
} }
else else
{ {
@ -157,7 +163,7 @@ void NumKeyDia::on_btn_ok_clicked()
} }
if(m_isDouble) if(m_isDouble)
m_pLineEdit->setText(QString::number(_d, 10, 3)); m_pLineEdit->setText(QString::number(_d, m_format, m_prec));
else else
m_pLineEdit->setText(QString::number(_d, 10, 0)); m_pLineEdit->setText(QString::number(_d, 10, 0));
} }

2
numkeydia.h

@ -56,6 +56,8 @@ private:
double m_maxValue = 0.000; double m_maxValue = 0.000;
bool m_isNum = false; bool m_isNum = false;
bool m_isDouble = false; bool m_isDouble = false;
char m_format = 'f';
int m_prec = 3;
}; };
#endif // NUMKEYDIA_H #endif // NUMKEYDIA_H

Loading…
Cancel
Save