PDA

View Full Version : qtextedit capturing the enter key



tas
23rd February 2007, 23:42
I need to have rich text editing in a qlineedit so I am altering a qtextedit to work the same. I have succeeded in everything except I need to capture the enter key to make it submit.

My problem now is I can capture the enter key but it captures all keys and the rest dont make it to the text area. So I am trying to ignore the event when it is any other key but the enter key but it doesnt ignore the event and still captures them. Does anyone have any ideas?



void InputBox::keyPressEvent(QKeyEvent *event){
if(event->key()==Qt::Key_Return){
doAction()
}
else event->ignore();
}


I tried inserting the text manually into the text area but I ran into the problem of other keys such as the backspace trying to be inserted which shows up as a box

jacek
24th February 2007, 00:12
Try:

void InputBox::keyPressEvent(QKeyEvent *event){
if(event->key()==Qt::Key_Return){
doAction()
}
else {
QTextEdit::keyPressEvent( event );
}
}

tas
24th February 2007, 00:35
Thank you that worked perfectly.