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. Change increment amount
Forum Updated to NodeBB v4.3 + New Features

Change increment amount

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 473 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.
  • K Offline
    K Offline
    kebabman123
    wrote on last edited by
    #1

    Hi!
    I have a button and when i press it a spinbox increases it value by one (onclick() Stepup())
    The problem i have is that i also have a QLineEdit which i can type a number into.
    If i type 3 in the QlineEdit i want the button to increase the Spinbox by 3 and not the default 1.
    How would i go about making it so that the button increases the Spinbox value with the number that is in the QLineEdit?!b6ed8406a140d0b098531c05a01222fe.png

    JonBJ 1 Reply Last reply
    0
    • K kebabman123

      Hi!
      I have a button and when i press it a spinbox increases it value by one (onclick() Stepup())
      The problem i have is that i also have a QLineEdit which i can type a number into.
      If i type 3 in the QlineEdit i want the button to increase the Spinbox by 3 and not the default 1.
      How would i go about making it so that the button increases the Spinbox value with the number that is in the QLineEdit?!b6ed8406a140d0b098531c05a01222fe.png

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by JonB
      #2

      @kebabman123
      When the user types whatever into the line edit get that number and pass it to QSpinBox::setSingleStep(int val).

      P.S.
      If your line edit, with the + & - buttons, is used to enter a number that itself should also be (another) QSpinBox :)

      K 1 Reply Last reply
      1
      • JonBJ JonB

        @kebabman123
        When the user types whatever into the line edit get that number and pass it to QSpinBox::setSingleStep(int val).

        P.S.
        If your line edit, with the + & - buttons, is used to enter a number that itself should also be (another) QSpinBox :)

        K Offline
        K Offline
        kebabman123
        wrote on last edited by
        #3

        @JonB Thanks for the fast reply!
        Im very new to this and dont really know how to get the number from the line edit.
        How would i go about getting this number so that i can send it to the spinbox?

        JonBJ 1 Reply Last reply
        0
        • K kebabman123

          @JonB Thanks for the fast reply!
          Im very new to this and dont really know how to get the number from the line edit.
          How would i go about getting this number so that i can send it to the spinbox?

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by
          #4

          @kebabman123
          You must learn Signals & Slots, else you won't be able to do anything in Qt.

          Then you decide exactly when you want to "accept" and act on the new number being typed in:

          • QLineEdit::textChanged, QLineEdit::textEdited or QSpinBox::valueChanged are signals which are all emitted when a change is made while editing.
          • QLineEdit::editingFinished is a signal emitted after a user has finished editing and moves off the line edit.

          Pick whichever of these you want. Attach a slot to it. Read the value and use that to change the step size on the other spin box.

          K 2 Replies Last reply
          1
          • JonBJ JonB

            @kebabman123
            You must learn Signals & Slots, else you won't be able to do anything in Qt.

            Then you decide exactly when you want to "accept" and act on the new number being typed in:

            • QLineEdit::textChanged, QLineEdit::textEdited or QSpinBox::valueChanged are signals which are all emitted when a change is made while editing.
            • QLineEdit::editingFinished is a signal emitted after a user has finished editing and moves off the line edit.

            Pick whichever of these you want. Attach a slot to it. Read the value and use that to change the step size on the other spin box.

            K Offline
            K Offline
            kebabman123
            wrote on last edited by
            #5

            @JonB 7d0ea0d3f0ed85634593181475a53922.png Is this what you mean? Because it is giving me errors.

            jsulmJ 1 Reply Last reply
            0
            • JonBJ JonB

              @kebabman123
              You must learn Signals & Slots, else you won't be able to do anything in Qt.

              Then you decide exactly when you want to "accept" and act on the new number being typed in:

              • QLineEdit::textChanged, QLineEdit::textEdited or QSpinBox::valueChanged are signals which are all emitted when a change is made while editing.
              • QLineEdit::editingFinished is a signal emitted after a user has finished editing and moves off the line edit.

              Pick whichever of these you want. Attach a slot to it. Read the value and use that to change the step size on the other spin box.

              K Offline
              K Offline
              kebabman123
              wrote on last edited by
              #6

              @JonB Thanks for all your help i actually got it working with this code!
              int textValue = ui->lineEdit->text().toInt();
              int spinBoxValue = ui->spinBox->value();
              spinBoxValue += textValue;
              ui->spinBox->setValue(spinBoxValue);

              If anyone else was wondering

              1 Reply Last reply
              0
              • K kebabman123 has marked this topic as solved on
              • K kebabman123

                @JonB 7d0ea0d3f0ed85634593181475a53922.png Is this what you mean? Because it is giving me errors.

                jsulmJ Online
                jsulmJ Online
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @kebabman123 said in Change increment amount:

                Because it is giving me errors

                Because you need to call this method on an instance of QSpinBox

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0

                • Login

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