如何对子类 QTextEdit 进行编码以在“输入”按键上引起“插槽”调用?
//mainwindow.cpp
myTextEdit *mytext = new myTextEdit(this);
mytext->setGeometry(QRect(QPoint(10,20), QSize(100,50)));
connect(mytext, SIGNAL(myReturn()), this, SLOT(handleText()));
//subclassed QTextEdit
void myTextEdit::keyPressEvent(QKeyEvent *e)
{
QString qstr = ::myTextEdit::toPlainText();
if(e->key() == 16777220){ //enter key
qstr = qstr + "\r\n>> ";
//now cause an event like a QPushButton "released()" event to cause a "slot" call
}else{
qstr = qstr + e->key();
}
::myTextEdit::setText(qstr);
}