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
QtWS25 Last Chance

How to construct a doubleSpinBox with default minimum and maximum value

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 383 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 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
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on 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 last edited by
        #3

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

        mrjjM 1 Reply Last reply
        0
        • S summit

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

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on 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 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 ?

            mrjjM 1 Reply Last reply
            0
            • S summit

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

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on 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
              1
              • mrjjM 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 Offline
                S Offline
                summit
                wrote on last edited by summit
                #7

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

                1 Reply Last reply
                1

                • Login

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