Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to construct a doubleSpinBox with default minimum and maximum value
Forum Update on Monday, May 27th 2025

How to construct a doubleSpinBox with default minimum and maximum value

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 392 Views
  • 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 Offline
    S Offline
    summit
    wrote on 27 Aug 2020, 13:55 last edited by
    #1

    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
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 27 Aug 2020, 13:59 last edited by
      #2

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

      1 Reply Last reply
      1
      • S Offline
        S Offline
        summit
        wrote on 27 Aug 2020, 14:03 last edited by
        #3

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

        M 1 Reply Last reply 27 Aug 2020, 14:05
        0
        • S summit
          27 Aug 2020, 14:03

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

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 27 Aug 2020, 14:05 last edited by mrjj
          #4

          @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
          1
          • S Offline
            S Offline
            summit
            wrote on 27 Aug 2020, 14:16 last edited by
            #5

            @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 ?

            M 1 Reply Last reply 27 Aug 2020, 14:19
            0
            • S summit
              27 Aug 2020, 14:16

              @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 ?

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 27 Aug 2020, 14:19 last edited by mrjj
              #6

              @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 27 Aug 2020, 14:23
              1
              • M mrjj
                27 Aug 2020, 14:19

                @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 Offline
                S Offline
                summit
                wrote on 27 Aug 2020, 14:23 last edited by summit
                #7

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

                1 Reply Last reply
                1

                1/7

                27 Aug 2020, 13:55

                • Login

                • Login or register to search.
                1 out of 7
                • First post
                  1/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved