ehudson
ehudson

Reputation: 205

QDoubleSpinBox: Stop emitting intermediate values

I am subclassing QDoubleSpinBox to add some features (like incrementing the value based on the location of the cursor in the lineedit) and to change some features I find annoying. One of the latter is that intermediate values are emitted: e.g. if you want to enter the value 323 it will emit 3 then 32 then finally 323. I'd like to set it to only emit on entry (i.e. only actually change value on entry).

Anyway, I can't figure out how to capture these intermediate edits. I overrode setValue to see if I could stop it there somehow, but it apparently isn't called (or at least my override isn't). I'm not sure how the value is actually getting set while editing in line edit.

More generally, the logic of this box escapes me. Is there some documentation that explains e.g. "if you type a digit into the lineedit then this series of routines is called... while if you hit the up arrow, this series of routines is called?"

In case it matters, I'm using PyQt5

EDIT: Here is another case in which having access to this is important. Say I want to implement an undo/redo structure for the box. The only way I can think of to get access to the changed values is to connect to the valueChanged signal. But if I'm subclassing the box it seems a little convoluted to listen for a signal rather than just watch the value change 'internally' Or am I missing something here?

Upvotes: 2

Views: 1094

Answers (2)

Ruslan
Ruslan

Reputation: 19140

My use case was to let the user enter the value without getting the signal on each new digit, while still making , , Page Up, Page Down keys and arrow buttons work as usual, emitting the signal on each activation.

QAbstractSpinBox::editingFinished signal doesn't provide this functionality: it's only ever emitted when focus is lost or Return/Enter is pressed.

What does work exactly as I need is the keyboardTracking property of QAbstractSpinBox. If it's true (the default), the spinbox emits valueChanged on each digit typed. If you set it to false, it behaves exactly as I described in the beginning of this answer.

Upvotes: 2

László Papp
László Papp

Reputation: 53215

You could use the following signal:

void QAbstractSpinBox::editingFinished() [signal]

This signal is emitted editing is finished. This happens when the spinbox loses focus and when enter is pressed.

based on the documentation of QAbstractSpinBox:

http://qt-project.org/doc/qt-5.1/qtwidgets/qabstractspinbox.html#editingFinished

There is nothing that combines the arrow based changes and the editingFinished changes.

Upvotes: 2

Related Questions