如何将过滤后的键写入子类 QTextEdit 屏幕?
#ifndef TEXTEDIT_H
#define TEXTEDIT_H
#include <QWidget>
#include <QTextEdit>
#include <QMessageBox>
#include <QKeyEvent>
class TextEdit : public QTextEdit
{
Q_OBJECT
public:
explicit TextEdit(QString qstr, QWidget *parent = 0);
QString m_qstr;
protected:
virtual void keyPressEvent(QKeyEvent *e);
signals:
public slots:
};
#endif // TEXTEDIT_H
#include "textedit.h"
TextEdit::JDLTextEdit(QString _qstr, QWidget *parent) :
QTextEdit(_qstr, parent)
{
}
void TextEdit::keyPressEvent(QKeyEvent *e)
{
if(e->key() == 16777220){ //"enterKey"
QString qstr = QString::number(e->key(), 'd',0);
QMessageBox *msgBox = new QMessageBox(0);
msgBox->setGeometry(QRect(QPoint(200,200),QSize(400,400)));
msgBox->setInformativeText(qstr);
msgBox->exec();
}else{
//write key chars to the QTextEdit screen
}
}