Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

qt

qspinbox

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?

like image 679
Ufx Avatar asked Nov 17 '25 23:11

Ufx


1 Answers

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.

like image 85
p.i.g. Avatar answered Nov 19 '25 14:11

p.i.g.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!