pyqt: return pressed signal for spinbox?
Asked Answered
H

2

8

There are signals valueChanged() and editingFinished(), but I need perform my action only when key enter is pressed.

Is there any solution without reimplementing event handler?

I need to change focus to the next spinbox on pressed enter key. Any idea?

Heteronym answered 28/3, 2016 at 16:17 Comment(0)
A
8

Use setKeyboardTracking(False)

If keyboard tracking is disabled, the spinbox doesn't emit the valueChanged() signal while typing. It emits the signal later, when the return key is pressed, when keyboard focus is lost, or when other spinbox functionality is used, e.g. pressing an arrow key.

Amadoamador answered 28/3, 2016 at 18:10 Comment(2)
Added better description what I need.Heteronym
This doesn't work for me because I need to know when you hit enter even if you haven't changed the value, and valueChanged doesn't fire in that case.Haemoglobin
B
2

You can access the underlying QLineEdit object which emits the desired returnPressed() signal:

spin_box = QSpinBox()   
spin_box.lineEdit().returnPressed.connect(self.spinBoxReturnPressed)

def spinBoxReturnPressed():
    ...
Bath answered 6/8, 2023 at 17:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.