PDA

View Full Version : Keyboard event and QTextEdit



kaszewczyk
2nd November 2009, 15:17
Hello,
i have problem with handling keyboard event, the problem is related to QTextEdit Widget the point is:
i have QTextEdit object for example called writeTextEdit and i installed on it event filter


this->writeTextEdit->installEventFilter(this);


next i implement eventFilter method


bool FooClass::eventFilter(QObject* _o, QEvent* _e){
if(_e->type() == QEvent::KeyPress){
QKeyEvent* eventKey = static_cast<QKeyEvent*>(_e);
if(eventKey->key() == Qt::Key_Return){
//do something
}
return true;
}else{
return QObject::eventFilter(_o, _e);
}
}


and when i run my app and want to write something in QTextEdit no letters are show inside, what is the problem?

Best Regards
kaszewczyk

Corinzio
2nd November 2009, 18:51
For what i see in your code for every key is pressed you check if the key is return then do something. if you are not pressing the return key you simply return true you should return the BaseClass eventFilter (thinking that FooClass extends QTextEdit).

Well maybe something like that:



bool FooClass::eventFilter(QObject* _o, QEvent* _e)
{
if(_e->type() == QEvent::KeyPress)
{
QKeyEvent* eventKey = static_cast<QKeyEvent*>(_e);
if(eventKey->key() == Qt::Key_Return)
{
//do something
return true;
}
}
return QTextEdit::eventFilter(_o, _e);
}

kaszewczyk
2nd November 2009, 19:30
Thanks work well :)

Best Regards
kaszewczyk