PDA

View Full Version : Problem reimplementing QWidget::keyPressEvent



jiveaxe
22nd September 2008, 12:23
Hi,
I need to change Tab key behavior for a QTextEdit so that when pressed the focus is passed to the next widget of the parent dialog (in tab order). So I have reimplemented void QWidget::keyPressEvent( QKeyEvent * event ) of my custom QTextEdit this way:


void CustomTextEdit::keyPressEvent(QKeyEvent *event)
{
switch (event->key()) {
case Qt::Key_Tab:
emit focusnextchild();
break;
default:
QWidget::keyPressEvent(event);
}
}

but now only the Tab key works (and the next widget is focused); pressing any other key (for inserting text in the textedit, for example) does nothing.

Where am I wrong?

spirit
22nd September 2008, 12:43
did you inherit your widget from QTextEdit?
if yes, then try


....
default:
QTextEdit::keyPressEvent(event);
....

jiveaxe
22nd September 2008, 13:02
Yes, spirit, you're right. Now works.

Thanks