Meloun
Meloun

Reputation: 15049

pyqt: return pressed signal for spinbox?

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?

Upvotes: 8

Views: 4839

Answers (2)

Marc
Marc

Reputation: 837

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():
    ...

Upvotes: 3

titusjan
titusjan

Reputation: 5546

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.

Upvotes: 9

Related Questions