[PyQt] QSpinBox does not recognize returnPressed event

Adrian Casey mail at agcasey.com
Wed May 11 10:13:24 BST 2011


I want to connect the returnPressed() event to a QSpinBox widget but it 
is not working.  I use the same approach with a QComboBox and it works.  
I'm using Qt 4.7.0 and PyQt on Kubuntu 10.10.

Here is a simple form containing a combobox and a spinbox.  Only the 
combobox registers the returnPressed event.

Can anyone tell me why the spinbox does not see the returnPressed event?

Thanks.
Adrian.

#!/usr/bin/python

# simple.py

import sys
from PyQt4 import QtGui
def do_it():
     print 'Return pressed!'

app = QtGui.QApplication(sys.argv)

widget = QtGui.QWidget()
widget.resize(250, 150)
widget.setWindowTitle('Signal Test')
layout = QtGui.QBoxLayout(2, widget)
cb = QtGui.QComboBox(widget)
cb.setEditable(True)
sb = QtGui.QSpinBox(widget)
layout.addWidget(sb)
layout.addWidget(cb)
cb.lineEdit().returnPressed.connect(do_it)
sb.lineEdit().returnPressed.connect(do_it)
widget.show()

sys.exit(app.exec_())


More information about the PyQt mailing list