当前位置: 代码迷 >> QT开发 >> 承袭QTextEditor后改了一下keyPressEvent(),然后不能向里面输入内容了
  详细解决方案

承袭QTextEditor后改了一下keyPressEvent(),然后不能向里面输入内容了

热度:32   发布时间:2016-04-25 03:51:02.0
继承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()处理
    }
}


------解决方案--------------------
额 这算低级错误嘛 哈哈.给我点分
------解决方案--------------------
自己动手,丰衣足食
  相关解决方案