C++ (Qt)#include <QDoubleSpinBox>#include <QDoubleValidator> class ScientificDoubleDpinBox : public QDoubleSpinBox{ Q_OBJECT public: explicit ScientificDoubleDpinBox(QWidget *parent = 0); void setMaximum(double max); void setMinimum(double min); void setDecimals(int prec); QValidator::State validate(QString &input, int &pos) const; double valueFromText(const QString &text) const; QString textFromValue(double val) const; void fixup(QString &str) const; private: QDoubleValidator *m_validator;};
C++ (Qt)#include <QLineEdit>#include "scientificdoubledpinbox.h" ScientificDoubleDpinBox::ScientificDoubleDpinBox(QWidget *parent) : QDoubleSpinBox(parent){ m_validator = new QDoubleValidator(this); m_validator->setNotation(QDoubleValidator::ScientificNotation);} void ScientificDoubleDpinBox::setMaximum(double max){ m_validator->setTop(max); QDoubleSpinBox::setMaximum(max);} void ScientificDoubleDpinBox::setMinimum(double min){ m_validator->setBottom(min); QDoubleSpinBox::setMinimum(min);} void ScientificDoubleDpinBox::setDecimals(int prec){ m_validator->setDecimals(prec); QDoubleSpinBox::setDecimals(prec);} QValidator::State ScientificDoubleDpinBox::validate(QString &input, int &pos) const{ return m_validator->validate(input, pos);} double ScientificDoubleDpinBox::valueFromText(const QString &text) const{ return text.toDouble();} QString ScientificDoubleDpinBox::textFromValue(double val) const{ return QString::number(val, 'e', decimals());} void ScientificDoubleDpinBox::fixup(QString &str) const{ return m_validator->fixup(str);}
C++ (Qt)MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){ ui->setupUi(this); ScientificDoubleDpinBox *sciDoubleSpinBox = new ScientificDoubleDpinBox(this); sciDoubleSpinBox->setMaximum(999999999.999999999); sciDoubleSpinBox->setMinimum(0.0); sciDoubleSpinBox->setDecimals(2); ui->verticalLayout->addWidget(sciDoubleSpinBox);}
C++ (Qt)double QDoubleSpinBoxPrivate::round(double value) const{ return QString::number(value, 'f', decimals).toDouble();}