[PyQt] QSpinBox and setLineEdit

Mads Ipsen mpi at comxnet.dk
Fri Jan 30 13:55:55 GMT 2009


--------- Original Besked --------
Fra: Matt Smith <melkor at orangepalantir.org>
Til: pyqt at riverbankcomputing.com <pyqt at riverbankcomputing.com>
Emne: Re: [PyQt] QSpinBox and setLineEdit
Dato: 30/01/09 14:11

> 
> &gt; 
> &gt; Well, OK. My problem is that I would like to connect up to the
> &gt; textChanged(const QString &amp;amp;) signal emitted by the spinbox's
lineedit.
> &gt; This
> &gt; signal, however, is only emitted when the edit is modified directly,
not
> &gt; when it changes indirectly eg. by pressing the up/down arrows on the
> &gt; spinbox. Any suggestions for a solution?
> &gt; 
> &gt; Mads
> &gt; 
> 
> QLine claims that the textChanged is emitted even when the text is
> changed programmatically.  Have you tried connecting to it?.
> 
>
http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qlineedit.html#textChanged
> 
> Your previous example did not involve connecting to the line edit.
> 
> mbs
> 
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
> 

Thanks for asking, this is exactly my point. If you connect to the line
edit, the connection is olny triggered if you edit the line edit directly.
If you press the arrows on the spin box. Nothing happens. The examples below
illustrates this:

import sys

from PyQt4 import QtCore, QtGui
        
def foo(text):
    print 'valueChanged():', text

if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    spin_box = QtGui.QSpinBox()
    line_edit = spin_box.lineEdit()
    line_edit.connect(line_edit, QtCore.SIGNAL('textChanged(const QString
&)'), foo)
    spin_box.show()
    sys.exit(app.exec_())


More information about the PyQt mailing list