How to tell when enter/return has been pressed in pyQt4 lineEdit
<p>I'm having a problem where I can't figure out how to tell if the user hits enter. All of the stackoverflow posts and docs I read all tell me to to add self.textEdit.returnPressed.connect, or something along the lines of that and none of the solutions work. I'm using pyQt 4. Here's the code:</p>

<pre><code># -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'untitled.ui'
#
# Created by: PyQt4 UI code generator 4.11.4
#
# WARNING! All changes made in this file will be lost!

import gi
import signal
gi.require_version('Gtk', '3.0')
import sys
import dbus
import pygtk
import gi
import signal
from PyQt4 import QtCore, QtGui
from PyQt4.QtCore import pyqtSlot
from PyQt4.QtCore import QUrl
from PyQt4.QtWebKit import QWebView

import sip
sip.setapi('QString', 2)
sip.setapi('QVariant', 2)

gi.require_version('Notify', '0.7')


try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s

try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(679, 600)
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))

        self.saveButton = QtGui.QPushButton(self.centralwidget)
        self.saveButton.setGeometry(QtCore.QRect(10, 0, 88, 28))
        self.saveButton.setObjectName(_fromUtf8("pushButton"))

        self.textEdit = QtGui.QTextEdit(self.centralwidget)
        self.textEdit.setGeometry(QtCore.QRect(0, 30, 681, 800))
        self.textEdit.setObjectName(_fromUtf8("textEdit"))

        self.fontButton = QtGui.QPushButton(self.centralwidget)
        self.fontButton.setGeometry(QtCore.QRect(400, 0, 88, 28))
        self.fontButton.setObjectName(_fromUtf8("fontButton"))

        self.fontSize = QtGui.QTextEdit(self.centralwidget)
        self.fontSize.setGeometry(QtCore.QRect(200, 0, 88, 28))
        self.fontSize.setObjectName(_fromUtf8("fontEdit"))
        self.fontSize.returnPressed.connect(self.pushButtonOK.click)

        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtGui.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 679, 24))
        self.menubar.setObjectName(_fromUtf8("menubar"))

        self.menuTest = QtGui.QMenu(self.menubar)
        self.menuTest.setObjectName(_fromUtf8("menuTest"))
        MainWindow.setMenuBar(self.menubar)

        self.statusbar = QtGui.QStatusBar(MainWindow)
        self.statusbar.setObjectName(_fromUtf8("statusbar"))
        MainWindow.setStatusBar(self.statusbar)
        self.menubar.addAction(self.menuTest.menuAction())

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

        @QtCore.pyqtSlot()
        def on_pushButtonOK_clicked(self):
            inputNumber = self.lineEditNumber.text()
            if inputNumber.isdigit():
                info = "You selected `{0}`"

            else:
                info = "Please select a number, `{0}` isn't valid!"

            print(info.format(inputNumber))

        #functions



        def save(self):
            with open('log.txt', 'w') as yourFile:
                yourFile.write(str(self.textEdit.toPlainText()))

        def saveFont(self):
            self.QtGui.QtFont.font.setPointSize(int(self.fontSize))


        def commander(self):
            save(self)

        self.saveButton.clicked.connect(lambda: save(self))
        self.fontButton.clicked.connect(lambda: save(self))



    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))
        self.saveButton.setText(_translate("MainWindow", "Save text", None))
        self.fontButton.setText(_translate("MainWindow", "Save Font", None))
        self.menuTest.setTitle(_translate("MainWindow", "test", None))

if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    MainWindow = QtGui.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())
</code></pre>

<p>You have to mistakes </p>

<ul>
<li><code>returnPressed</code> works with <code>QtLineEdit</code> and you use <code>QtTextEdit</code></li>
<li>you don't have <code>self.pushButtonOK</code> but <code>self.saveButton</code> and <code>self.fontButton</code></li>
</ul>

<p>So you need</p>

<pre><code>    self.fontSize = QtGui.QLineEdit(self.centralwidget)
    self.fontSize.setGeometry(QtCore.QRect(200, 0, 88, 28))
    self.fontSize.setObjectName(_fromUtf8("fontEdit"))
    self.fontSize.returnPressed.connect(self.fontButton.click)
</code></pre>

python python-3.x pyqt pyqt4