继承QTextEditor后改了一下keyPressEvent(),然后不能向里面输入内容了
#ifndef CODEEDITOR_H
#define CODEEDITOR_H
#include<QTextEdit>
//#include<QKeyEvent>
class CodeEditor:public QTextEdit
{
Q_OBJECT
protected:
void keyPressEvent(QKeyEvent *e);
};
#endif // CODEEDITOR_H
#include "codeeditor.h"
#include<QKeyEvent>
#include<QDebug>
#include<qwidget.h>
void CodeEditor::keyPressEvent(QKeyEvent *e)
{
switch(e->key())
{
case Qt::Key_Home:
qDebug()<<"press";
if(e->modifiers()&Qt::ControlModifier)
{
this->setText("KeyPress Success!!");
}
break;
default:
QWidget::keyPressEvent(e); //其他按键按QWidget的keyPressEvent()处理
}
}