2
I have a certain QLineEdit
in my application that when a QPushButton
is clicked, the text of it is sent to the database.
But I wish I could add that same event by pressing the ENTER key on that QLineEdit
.
How can I do that?
My code goes something like this:
def buildUi(self):
self.buttonSubmitText = QtWidgets.QPushButton("Enviar")
self.textChat = QtWidgets.QLineEdit()
self.buttonSubmitText.clicked.connect(self.onSubmitText)
def onSubmitText(self):
text = self.textChat.text()
message = create_message(self.selectedUser["id"], text)
formattedText = self._buildChatText(message)
self.viewChat.insertHtml(formattedText)
self.textChat.setText("")
In the above example, I want to press ENTER on self.textChat
, the method onSubmitText
be triggered.
How do I do?
Observing: I’m using Pyqt5, but you’re welcome to have answers with Pyqt4 for future reference.