Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved How to construct a doubleSpinBox with default minimum and maximum value

    General and Desktop
    2
    7
    128
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      summit last edited by

      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;
      };
      
      1 Reply Last reply Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        Hi
        Cant you just set the wanted value in the constructor ?

        1 Reply Last reply Reply Quote 1
        • S
          summit last edited by

          @mrjj can you please show the code line which will set the minimum value for the SpinBox

          mrjj 1 Reply Last reply Reply Quote 0
          • mrjj
            mrjj Lifetime Qt Champion @summit last edited by mrjj

            @summit
            It would just be in ctor.
            setMinimum( 0.0 );
            setMaximum(9999.0);

            like

             explicit SumDoubleBox(QWidget *parent = nullptr) : QDoubleSpinBox(parent)
                {
                    setMinimum(0.0);
                    setMaximum(9999.0);
                }
            
            
            1 Reply Last reply Reply Quote 1
            • S
              summit last edited by

              @mrjj Just one more query currently i am inheriting constructors using using QDoubleSpinBox::QDoubleSpinBox; // inherit c'tors

              so in this case i would not need this line of code ?

              mrjj 1 Reply Last reply Reply Quote 0
              • mrjj
                mrjj Lifetime Qt Champion @summit last edited by mrjj

                @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);
                    }
                ....
                
                
                S 1 Reply Last reply Reply Quote 1
                • S
                  summit @mrjj last edited by summit

                  @mrjj Thank you very much for your kind help as usual .

                  1 Reply Last reply Reply Quote 1
                  • First post
                    Last post