How to check if QSpinBox value changed by keyboard or buttons(mouse wheel)

1.3k views Asked by At

I need to set spinbox value to one of 1, 10, 100, 1000, 10000 if value changed by spinbox buttons or mouse wheel or up or down keys. But if value changed by keyboard I need other behavior.

Here is my code for buttons, mouse wheel, up and down keys.

void Dlg::onValueChanged(int value)
{
    if (value > _value)
        value = (value - 1) * 10;

    value = log10(value);
    value = _Pow_int(10, value);

    _ui->spinBoxs->setValue(_value = value);
}

How can I make other behavior for value changing by keyboard?

1

There are 1 answers

1
p.i.g. On BEST ANSWER

In this case I think you will have create your custom spinbox derived from QSpinBox. And you will need to reimplement at least the following functions:

virtual void keyPressEvent( QKeyEvent* event );
virtual void wheelEvent( QWheelEvent* event );

with your specification.