[PyQt] QSpinBox does not recognize returnPressed event

2011-05-11 Thread Adrian Casey
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_())
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] QSpinBox does not recognize returnPressed event

2011-05-11 Thread Hans-Peter Jansen
On Wednesday 11 May 2011, 11:13:24 Adrian Casey wrote:
 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?

From a cursory look, I would call this a Qt bug. Obviously, they handle 
the keyEvent for the return key in some way (by selecting the text), 
but forget to emit the signal, nor call the QLineEdit base class event 
method.

A look into the Qt source would clarify things and often gives an idea 
for a work around. As a starter, you could install some kind of event 
filter on the lineEdit widget and emit the signal yourself.

Pete

 #!/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_())
 ___
 PyQt mailing listPyQt@riverbankcomputing.com
 http://www.riverbankcomputing.com/mailman/listinfo/pyqt


___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt