When I want to connect a QPushButton
to an event, for example, I use a method and add it as callback of event clicked.connect
For example:
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("")
However I have seen several examples on the internet where QtCore.pyqtSlot()
is added as a decorator. That is, the code looks like this:
@QtCore.pyqtSlot()
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("")
I wonder what is the impact of using or not using this decorator? Does it make any difference?
Is it mandatory to use it or not?