How to construct a doubleSpinBox with default minimum and maximum value
Solved
General and Desktop
-
This is the class header file for a doubleSpin box which i am inheriting from QDoubleSpinBox.
currently after creating the box i have to set minimum to 0.0 and maximum value to 9999.0 explicitly
When ever i create DoubleSpinBox thee values should be set automatically.class SumDoubleBox : public QDoubleSpinBox { Q_OBJECT public: using QDoubleSpinBox::QDoubleSpinBox; // inherit c'tors // re-implement to keep track of default step (optional, could hard-code step in stepBy()) void setSingleStep(double val); // override to adjust step size double singleStep() const; void stepBy(int steps) override; private: double m_defaultStep = 1.0; double m_CurrentStep; bool m_stepUp; };
-
Hi
Cant you just set the wanted value in the constructor ? -
@summit
well you dont need that anymore since you provide your own and call the one you normally inherited.explicit SumDoubleBox(QWidget *parent = nullptr) : QDoubleSpinBox(parent) << call base !
{
setMinimum(0.0);
setMaximum(9999.0);
}so
class SumDoubleBox : public QDoubleSpinBox { Q_OBJECT public: //using QDoubleSpinBox::QDoubleSpinBox; // inherit c'tors explicit SumDoubleBox(QWidget *parent = nullptr) : QDoubleSpinBox(parent) { setMinimum(0.0); setMaximum(9999.0); } ....