Change increment amount
-
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?! -
@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
:) -
@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
orQSpinBox::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.
-
@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
-
-
@kebabman123 said in Change increment amount:
Because it is giving me errors
Because you need to call this method on an instance of QSpinBox