如何将过滤后的密钥写入子类QTextEdit屏幕
How to write filtered keys to a subclassed QTextEdit screen?
如何将过滤后的键写入子类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
}
}
使用::TextEdit::setText(qstr);
void TextEdit::keyPressEvent(QKeyEvent *e)
{
QString qstr = ::TextEdit::toPlainText();
//if(e->type() == QEvent::KeyPress){
if(e->key() == 16777220){
if(0){
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();
}
qstr = qstr + "rn>> ";
}else{
qstr = qstr + e->key();
}
::TextEdit::setText(qstr);
}
相关文章:
- 继承期间显示未知行为的子类
- 通过指向指针数组的指针访问子类的属性
- 从父类方法返回子类对象
- c++, 在子类中,如何在没有对象的情况下访问父类的方法?
- 将父类对象强制转换为子类的问题
- 避免在C++中重复子类定义
- 将QOpenGLWidget子类转换为使用Metal而不是OpenGL的子类是否可行?
- 如何初始化矢量的模板化子类
- C++ 继承:将子类传递给需要基类的函数并获取子类行为
- 有没有办法按值将纯抽象类的所有子类传递给 C++ 中的函数?
- 使用子类覆盖基类中定义的函数
- 子类地址等于虚拟基类地址?
- 将子类方法声明为基类的友元
- C++子类共享变量?
- 如何检查模板专用化是否是基本模板的子类?
- 仅让特定类'Fabric'构造类'Foo'及其所有子类的实例
- 使用模板参数重载C++方法:如何使其适用于模板的子类?
- 基类中的默认析构函数禁用子类中的移动构造函数(如果有成员)
- 覆盖QTextEdit子类中的keyPressEvent
- 如何将过滤后的密钥写入子类QTextEdit屏幕