重写QLineEdit使其可以发送"editingFinished(QString)"信号

#ifndef MYLINEEDIT

#define MYLINEEDIT

/* 

*重写QLineEdit使其可以发送"editingFinished(QString)"信号 

*/

#include 

#include

#include

class MyLineEdit : public QLineEdit

{

Q_OBJECT

public:

explicit MyLineEdit(QWidget *parent = 0):

QLineEdit(parent)

{

}

signals:

void editingFinished(QString);

protected:

virtual void keyPressEvent(QKeyEvent *e)

{

if (e->key() == Qt::Key_Return)

{

emit editingFinished(this->text());

}

QLineEdit::keyPressEvent(e);

}

virtual void focusOutEvent(QFocusEvent *e)

{

emit editingFinished(this->text());

QLineEdit::focusOutEvent(e);

}

};

#endif

你可能感兴趣的:(重写QLineEdit使其可以发送"editingFinished(QString)"信号)