PDA

View Full Version : SpinBox: received value depends on "up-down arrows", pressing enter or digit by hand



chobin
14th November 2012, 14:27
Hi,
I am a complete newbie as regards Qt and I have just started programming with it.
My problem regards SpinBox.

I need to distinguish if the value received from SpinBox depends on:
1. changing value using up down arrows
2. pressing enter
3. editing by hand the value (one digit at a time)

I have found that I can distinguish if the value is enter implementing _editingFinished() function as follows.
I wonder if there is something similar to the hasFocus property for understanding when the changed values depends on clicking up down arrows.




void MainWindow::on_doubleSpinBox_editingFinished()
{
if (ui->doubleSpinBox->hasFocus()) // Enter
{
qDebug() << "Enter pressed";
}
}

amleto
14th November 2012, 20:32
I have found that I can distinguish if the value is enter implementing
the value from a spinbox is never 'enter'.

have you read these?
qspinbox

qabstractspinbox

they don't don't have the signals you're after (for a pretty good reason)

ChrisW67
14th November 2012, 21:16
I need to distinguish if the value received from SpinBox depends on:
1. changing value using up down arrows
2. pressing enter
3. editing by hand the value (one digit at a time)

Why do you care how the value was entered? Seems an unusual thing, especially since item 2 does not change or set a value.

chobin
16th November 2012, 08:44
The project I am working on consists in a gui which sends data to a DSP.
At the changing of the spinBox value, a register in the DSP is updated.

When the up-down arrows of the SpinBox is used, the register is updated in the DSP, and this is ok.

When the SpinBox valued is changed by hand, at every digit modified, the value is updaetd in the DSP.
For example if the default value is 50.00 and I want to send the value 12.34, in the current state, I will send to the DSP uncomplete values (for example 10.00 -> 12.00 -> 12.30) before sending the value 12.34.

In order to avoid this I thought to discriminate if the value changed depends on:
1. by hand editing
2. up-down arrow clicking

If the the value has been edited by hand I need to catch the enter key (ignoring the digit modified by hand before the enter) and then to send the value to the DSP;
if the the value depends on up-down arrows clicking the value can be immediately send to the DSP.

Every suggestion is more than welcom!

amleto
16th November 2012, 10:12
The simplest solution is to add an 'apply' button. Then the user has control over when the DSP is updated.

chobin
16th November 2012, 10:47
Hi Amleto,

Thanks for your help!
As apply button do you mean to use a QLineEdit + a QPushButton?
Before deciding to modify the components of the GUI (actually I guess that the GUI users would not approve a similar change), I would prefer to evaluate some other solutions (if exist), even if more complicated.

amleto
16th November 2012, 13:19
No need to remove your spinbox. Spinbox + apply button.

If not acceptable, then you need to subclass QSPinBox or even QAbstractSpinBox

wysota
16th November 2012, 14:17
An alternative would be to use a timer that would apply the current value if it hasn't been changed for a while (e.g. 1 second). Such delay is acceptable and should allow the user to enter the value he really wants without passing intermediate values.