QSpinbox editingFInished signal on up/down arrow press
-
I went through a lot of posts regarding QSpinBox signals editingFinished and valueChanged, but not able solve my problem, ie,
- I want editingFinished signal to be emitted, when user enters any value and presses "Enter".[DONE]
- The user can change value with the up/down arrows either by keyPress or mousePress. This can be done by valueChange signal, but not editingFinished
So to achieve both, I'm facing problem, Suppose I want to enter 10000, so valueChanged is emitted with 1, 10, 100, 1000, 10000 Which I don't want, rather it should emit when user pressed enter after entering 10000. So this is done by avoiding valueChanged and connecting to &QAbstractSpinbox::editingFinished.
connect(ui->spinBox, &QSpinBox::editingFinished, this, [&]() { ui->label->setText(QString::number(ui->spinBox->value())); });
But I want the up/down arrows to work also. so for this again valueChanged is required.
Is there any means to achieve it directly, rather than adding my own spinbox class and overriding the events for up/down arrow click/press.
Any suggestion is appreciated.
-
@sayan275 I think this is exactly what you need: https://doc.qt.io/qt-5/qabstractspinbox.html#keyboardTracking-prop
-
@sayan275 said in QSpinbox editingFInished signal on up/down arrow press:
rather it should emit when user pressed enter
So, do you expect your users to use up/down and submit the result with enter? This would be unusual and counter-intuitive.
-
@Pradeep-P-N
Thanks
I kept that as the last option. -
@sayan275 OK, I think I understand now what you want to achieve. But what would happen if user would use up/down keys without pressing enter when finished? User would expect that the current value will take effect but it will not (as he/she did not press enter). You would need to make it clear for the user that the value needs to be submitted using enter key.
-
@jsulm
Case 1: If user presses arrow keys...the value would change...no enter required to be pressed
Case 2: if user enters some value in the spinbox, it shouldn't emit valueChanged, unless enter is pressed.
Because, what happens is, If user wants to enter 10000, so 5 times valueChanged will emit, with 1, 10, 100, 1000, 10000.
But it should be only once when user hits enter after entering 10000. This is done by editingFinished and not handling valueChanged. But then the value can't be changed from arrow keys, as valueChanged is not connected. -
@sayan275 I think this is exactly what you need: https://doc.qt.io/qt-5/qabstractspinbox.html#keyboardTracking-prop