[PyQt] Pressing enter in QLineEdit clicks QPushButton?

Sibylle Koczian Sibylle.Koczian at t-online.de
Sat Jun 20 18:53:18 BST 2009


I've got a dialog with a QLineEdit and a QPushButton. The QLineEdit is
connected to a method which takes its text and appends it to a
QTextBrowser (that's taken from the first GUI example in the PyQt book
by M. Summerfield). The "clicked()" signal of the QPushButton is
connected to a method that just prints a message. The problem: this
method, which should only be called by clicking the button, is called
every time Enter is pressed in the QLineEdit. This happens even if the
edit control isn't connected to any method.

The button is next to the line edit in the form and in the tab order.

With "setAutoDefault(false)" for this button and for the exit button
which follows in tab order I can prevent this behavior, but that isn't
really very comfortable. And it shouldn't be necessary, should it?

All this on openSUSE with Python 2.6, PyQt 4.4.4.

Thank you for help,

Sibylle Koczian

More information about the PyQt mailing list