D
Read the warnings to the console during your program.Signed:Object::connect: No such slot QTextEdit: EnterPressed()You tried to connect the signal to a elephant that doesn't exist.Yeah, and besides, class. QTextEditwhich you use doesn't have a signal. returnPressed()♪ This signal is in class. QLineEditFor example. http://doc.qt.io/qt-4.8/qtextedit.html#signals ♪Fixed your example using QLineEdit:class Test(QtCore.QObject):
def __init__(self, parent = None):
QtCore.QObject.__init__(self, parent)
@QtCore.pyqtSlot()
def EnterPressed(self):
print("blabla")
if name == "main":
import sys
app = QtGui.QApplication(sys.argv)
ptxt1 = QtGui.QLineEdit()
ptxt2 = QtGui.QLineEdit()
ptxt3 = QtGui.QLineEdit()
ptxt1.setText("1")
ptxt2.setText("2")
ptxt3.setText("3")
tst = Test()
QtCore.QObject.connect(ptxt1, QtCore.SIGNAL("returnPressed()"), tst, QtCore.SLOT("EnterPressed()"))
spl1=QtGui.QSplitter(QtCore.Qt.Vertical)
spl2=QtGui.QSplitter(QtCore.Qt.Horizontal,spl1)
spl1.addWidget(ptxt1)
spl2.addWidget(ptxt2)
spl2.addWidget(ptxt3)
spl1.resize(500, 500)
spl1.show()
spl2.show()
sys.exit(app.exec_())
Now I'll explain the steps.class Test(QtCore.QObject): - identified his class inherited.
from QObject♪ Someone has to accept the signal.The designer just called the base class designer. Described actions performed by the signal response: @QtCore.pyqtSlot()
def EnterPressed(self):
print("blabla")
Note that any slot is Not static On a class basis, it is it necessary to refer the reference to the object for which the method will be called first (and in this example the only) argument.Functions main created the object tst - A copy of the class Test:tst = Test()
Connected the signal from the target. QTextEdit with a layer of object tst:QtCore.QObject.connect(self.ptxt1, QtCore.SIGNAL("textChanged()"), tst, QtCore.SLOT("EnterPressed()"))
That's what you wanted.